1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
---
title: Introduction to the JavaScript shell
slug: Introduction_to_the_JavaScript_shell
tags:
- 스파이더몽키
translation_of: Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell
---
<p>{{SpiderMonkeySidebar("General")}}</p>
<p>자바스트립트 셸(JavaScript shell)은 스파이더몽키에 포함된 커맨드라인 프로그램입니다. 이는 파이썬의 인터랙티브 프롬프트, Lisp read-eval-print 루프, 또는 루비의 <code>irb</code>와 같습니다. 이 문서는 셸을 이용해 자바스크립트 코드를 시험하고, 자바스크립트 프로그램을 실행하는 방법에 대해 소개합니다.</p>
<p>스파이더몽키 자바스크립트 셸을 설치하기 위해서는 <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation">SpiderMonkey Build Documentation</a>를 참고하거나, <a class="external external-icon" href="https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/" title="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">Nightly Builds</a>에서 사용 중인 플랫폼에 맞는 컴파일된 바이너리를 다운로드하세요.</p>
<p>다른 자바스크립트 셸 리스트를 보고 싶다면 <a class="internal" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells" title="En/JavaScript shells">JavaScript shells</a>를 참고하세요.</p>
<h2 id=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0" name=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0">자바스크립트 셸 설치하기</h2>
<h3 id="CVS_.EC.84.9C.EB.B2.84.EC.97.90_.EC.A0.91.EC.86.8D.ED.95.A9.EC.8B.9C.EB.8B.A4" name="CVS_.EC.84.9C.EB.B2.84.EC.97.90_.EC.A0.91.EC.86.8D.ED.95.A9.EC.8B.9C.EB.8B.A4">CVS 서버에 접속합시다</h3>
<p>CVS에서 다른 모질라와 관련된 프로젝트의 산물을 얻는 것과 마찬가지로 자바스크립트 셸을 사용하려면 먼저 CVS 서버에 로그인해야 합니다. cd 명령을 사용하여 코드를 체크아웃할 기본 디렉토리로 들어가, 다음과 같은 명령어를 명령행에 입력합니다.</p>
<pre class="eval">cvs -d <a class="link-mailto" href="mailto::pserver:anonymous@cvs-mirror.mozilla.org" rel="freelink">:pserver:anonymous@cvs-mirror.mozilla.org</a>:/cvsroot login
</pre>
<p>프롬프트가 뜨면 패스워드를 입력합니다. anonymous 라고 입력하면 됩니다.</p>
<h3 id=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.ED.8A.B8.EB.A0.81.ED.81.AC_.EB.B2.84.EC.A0.84_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0" name=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.ED.8A.B8.EB.A0.81.ED.81.AC_.EB.B2.84.EC.A0.84_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0">자바스크립트 셸 트렁크 버전 설치하기</h3>
<p>한번 CVS 서버에 로그인하였으면 필요한 파일을 받아와야 합니다. 트렁크란 CVS에서 중심이 되는 개발 흐름을 말합니다. 트렁크 버전을 다운로드 하기 위해 CVS 트리의 루트로 지정한 디렉토리로 들어가 다음과 같이 명령을 입력합니다.</p>
<pre>cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co -l mozilla/js/src mozilla/js/src/config mozilla/js/src/editline mozilla/js/src/fdlibm
</pre>
<p>자바스크립트 셸을 설치하는 데 필요한 모든 파일을 체크아웃하였습니다. 이제 다음과 같은 명령 두개만 입력하면 바로 설치할 수 있습니다:</p>
<pre>cd mozilla/js/src
make -f Makefile.ref
</pre>
<p>컴파일이 끝나면 우리가 설치한 디렉토리에 실행할 수 있는 파일인 js가 들어 있어야 합니다. 예를 들어 Mac OS X에서라면, 실행 파일은 Darwin_DBG.OBJ/js의 경로에 놓일 것입니다.</p>
<p>이 상태에서 바로 <a href="#Using_the_JavaScript_shell">자바스크립트 셸 사용하기</a>를 실습해 볼 수도 있습니다.</p>
<h3 id=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EB.B8.8C.EB.9E.9C.EC.B9.98_.EB.B2.84.EC.A0.84_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0" name=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EB.B8.8C.EB.9E.9C.EC.B9.98_.EB.B2.84.EC.A0.84_.EC.84.A4.EC.B9.98.ED.95.98.EA.B8.B0">자바스크립트 셸 브랜치 버전 설치하기</h3>
<p>간단히 설명하면 브랜치란 중심이 되는 개발 흐름에서 곁가지를 쳐 나온, 작은 부분에 대한 개발 흐름을 뜻합니다. 자바스크립트 셸의 실험적이고 독특한 브랜치 버전을 사용하기를 원한다면 파일을 체크아웃 할 때 <code>-r <em>branchname</em> </code>을 추가하는 것만으로도 바로 사용할 수 있습니다.</p>
<p>설치 과정은 트렁크 버전과 같으나, 체크아웃을 할 때 cvs co... 행의 내용이 조금 바뀝니다.</p>
<pre class="eval">cvs -d <a class="link-mailto" href="mailto::pserver:anonymous@cvs-mirror.mozilla.org" rel="freelink">:pserver:anonymous@cvs-mirror.mozilla.org</a>:/cvsroot co -l -r<em>branch_name</em> mozilla/js/src mozilla/js/src/config mozilla/js/src/editline mozilla/js/src/fdlibm
</pre>
<p><em>branch_name</em>을 체크아웃하기 원하는 브랜치 버전의 이름으로 변경하세요. 예를 들어 JavaScript 1.7 의 알파 브랜치인, JS_1_7_ALPHA_BRANCH로 변경할 수 있습니다.</p>
<p>컴파일하는 방법은 앞서 설명한 방법과 같습니다.</p>
<h2 id=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EC.82.AC.EC.9A.A9.ED.95.98.EA.B8.B0" name=".EC.9E.90.EB.B0.94.EC.8A.A4.ED.81.AC.EB.A6.BD.ED.8A.B8_.EC.85.B8_.EC.82.AC.EC.9A.A9.ED.95.98.EA.B8.B0">자바스크립트 셸 사용하기</h2>
<p>자바스크립트 셸은 두가지 모드로 운영할 수 있습니다. 먼저 여러분은 여러분이 새로운 자바스크립트 코드를 테스트하기 위해 프롬프트에 직접 입력하고 결과를 바로 얻는, 인터랙티브 셸로 사용할 수도 있습니다. 혹은 자바스크립트 프로그램 파일을 명령행에 입력하여 실행할 수도 있습니다.</p>
<div class="note"><strong>노트:</strong> 자바스크립트 셸은 자바스크립트 엔진을 위한 테스트 환경입니다. 그러므로 사용 가능한 함수나 옵션은 변경될 수 있습니다.</div>
<h3 id=".EB.AA.85.EB.A0.B9.ED.96.89_.EC.98.B5.EC.85.98" name=".EB.AA.85.EB.A0.B9.ED.96.89_.EC.98.B5.EC.85.98">명령행 옵션</h3>
<p>셸을 설정하고 사용하는 데 필요한 명령들입니다. 간단히 요약하면 다음과 같습니다.</p>
<ul>
<li><code>-b<em>branchlimit</em> </code>
<ul>
<li>최대 브랜치 개수를 정합니다.</li>
</ul>
</li>
<li><code>-c<em>stackchunksize</em> </code>
<ul>
<li>스택 덩어리의 크기를 정합니다.</li>
</ul>
</li>
<li><code>-C</code>
<ul>
<li>프로그램을 컴파일만 하고 실행은 하지 않습니다. 굳이 실행하지 않고도 문법 에러를 빠르게 확인할 때 사용할 수 있습니다.</li>
</ul>
</li>
<li><code>-e<em>script</em> </code>
<ul>
<li>해당<em>script</em> 를 실행합니다. 해당 스크립트 안에는 실행할 수 있는 코드가 들어 있어야 합니다.</li>
</ul>
</li>
<li><code>-f<em>filename</em> </code>
<ul>
<li><em>filename</em>에 해당하는 자바스크립트 프로그램을 실행합니다.</li>
</ul>
</li>
<li><code>-i</code>
<ul>
<li>인터랙티브 모드를 활성화합니다.</li>
</ul>
</li>
<li><code>-P</code>
<ul>
<li><em>이 문서의 저자도 아직 확실히 무슨 옵션인지 모르겠다는군요. :-)</em></li>
</ul>
</li>
<li><code>-s</code>
<ul>
<li>정적 경고모드를 활성화합니다.</li>
</ul>
</li>
<li><code>-S<em>stacksize</em> </code>
<ul>
<li>최대 스택 크기를 정합니다.</li>
</ul>
</li>
<li><code>-v</code>
<ul>
<li>경고 정보를 봅니다.</li>
</ul>
</li>
<li><code>-w</code>
<ul>
<li>경고 메시지 보기를 활성화합니다.</li>
</ul>
</li>
<li><code>-W</code>
<ul>
<li>경고 메시지 보기를 불활성화합니다.</li>
</ul>
</li>
<li><code>-x</code>
<ul>
<li>E4X XML 모드를 활성화합니다.</li>
</ul>
</li>
</ul>
<h3 id=".EC.85.B8_.EC.8B.A4.ED.96.89.ED.95.98.EA.B8.B0" name=".EC.85.B8_.EC.8B.A4.ED.96.89.ED.95.98.EA.B8.B0">셸 실행하기</h3>
<p>인터랙티브 모드로 셸을 실행하고 싶다면 다음과 같이 입력합니다.:</p>
<pre class="eval">js
</pre>
<p>foo.js라는 파일을 불러 실행하고 싶다면 다음과 같이 입력합니다.:</p>
<pre class="eval">js -f foo.js
</pre>
<p>foo.js를 실행하고 나서 인터랙티브 셸로 전환하고 싶다면 다음과 같이 할 수 있습니다:</p>
<pre class="eval">js -f foo.js -f -
</pre>
<h4 id=".EC.9D.B8.ED.84.B0.EB.9E.99.ED.8B.B0.EB.B8.8C_.EB.AA.A8.EB.93.9C.EC.97.90.EC.84.9C_.EC.85.B8_.EC.82.AC.EC.9A.A9.ED.95.98.EA.B8.B0" name=".EC.9D.B8.ED.84.B0.EB.9E.99.ED.8B.B0.EB.B8.8C_.EB.AA.A8.EB.93.9C.EC.97.90.EC.84.9C_.EC.85.B8_.EC.82.AC.EC.9A.A9.ED.95.98.EA.B8.B0">인터랙티브 모드에서 셸 사용하기</h4>
<p>인터랙티브 모드에서 당신은 손으로 직접 오브젝트와 함수들을 입력하여 자바스크립트를 실행하고 구문들을 테스트해 볼 수 있습니다. 이것은 우리의 아이디어를 시험해보기 편리한 방법이며, 자바스크립트 엔진을 사용하는 개발자들이 이 언어의 새로운 요소들을 시험해보는 중요한 장이기도 합니다.</p>
<h3 id=".EB.B9.8C.ED.8A.B8-.EC.9D.B8_.ED.95.A8.EC.88.98" name=".EB.B9.8C.ED.8A.B8-.EC.9D.B8_.ED.95.A8.EC.88.98">빌트-인 함수</h3>
<p>자바스크립트 셸을 더욱 유용하게 사용하기 위하여, 당신이 자바스크립트 프로그램이나 인터랙티브 모드에서 사용할 수 있는 함수들이 준비되어 있습니다.</p>
<h4 id="build.28.29" name="build.28.29"><code>build()</code></h4>
<p>자바스크립트 셸이 빌드된 시간과 날짜를 반환합니다.</p>
<h4 id="clear.28.5Bobject.5D.29" name="clear.28.5Bobject.5D.29"><code>clear(<em>[object]</em> )</code></h4>
<p><var>object</var>의 속성들을 비웁니다. 다른 옵션 없이 <code>clear()</code>라고만 실행하면 모든 속성이 초기화됩니다.</p>
<div class="note"><strong>Note:</strong> 다른 옵션 없이 <code>clear()</code> 를 실행하면 정말로 모든 것이 지워집니다. 지금 설명하는 빌트-인 함수들도 포함해서 말이지요.</div>
<h4 id="clone.28function.2C_.5Bscope.5D.29" name="clone.28function.2C_.5Bscope.5D.29"><code>clone(<em>function, [scope]</em> )</code></h4>
<p>해당 <var>function</var>의 오브젝트들을 복제합니다. <var>scope</var>가 따로 정해지지 않았다면 새로운 오브젝트의 부모 요소는 기존의 것과 완전히 동일해집니다. 기존 함수에서 일부만을 떼어 복사하고 싶다면 <var>scope</var>로 범위를 지정해 주세요.</p>
<h4 id="dis.28.5Bfunction.5D.29" name="dis.28.5Bfunction.5D.29"><code>dis(<em>[function]</em> )</code></h4>
<p>다른 프로그램에 사용하거나 특별한 함수로 만들기 위해 자바스크립트를 바이트코드로 만드는(디스어셈블 하는) 함수입니다.</p>
<p>예를 들어 다음과 같은 자바스크립트가 있다고 합시다.</p>
<pre>function test() {
var i = 3;
print(i+2);
}
</pre>
<p>dis(test);를 실행하면 다음과 같은 결과를 볼 수 있습니다:</p>
<pre>main:
00000: uint16 3
00003: setvar 0
00006: pop
00007: name "print"
00010: pushobj
00011: getvar 0
00014: uint16 2
00017: add
00018: call 1
00021: pop
00022: stop
Source notes:
0: 0 [ 0] newline
1: 3 [ 3] var
2: 7 [ 4] newline
3: 18 [ 11] xdelta
4: 18 [ 0] pcbase offset 11
</pre>
<h4 id="dissrc.28.5Bfunction.5D.29" name="dissrc.28.5Bfunction.5D.29"><code>dissrc(<em>[function]</em> )</code></h4>
<p>다른 프로그램에 사용하거나 특별한 함수로 만들기 위해 자바스크립트를 바이트코드로 만들고 소스를 보여주는 함수입니다. 이 함수는 파일에서 로딩된 함수에만 적용할 수 있으며, 셸에서 명령을 입력할 때에도 <code>-f</code> 옵션을 주거나 <code>load()</code> 함수를 사용해야 합니다.</p>
<p>당신의 프로그램에 <code>doStuff()</code> 함수가 포함되어 있다고 가정합시다.</p>
<pre>function doStuff(input) {
print("Enter a number: ");
var n1 = readline();
print("Enter another one: ");
var n2 = readline();
print("You entered " + n1 + " and " + n2 + "\n");
}
</pre>
<p>그러면 <code>dissrc(doStuff)</code> 함수를 실행한 결과를 보겠습니다.:</p>
<pre>;------------------------- 10: print("Enter a number: ");
00000: 10 name "print"
00003: 10 pushobj
00004: 10 string "Enter a number: "
00007: 10 call 1
00010: 10 pop
;------------------------- 11: var n1 = readline();
00011: 11 name "readline"
00014: 11 pushobj
00015: 11 call 0
00018: 11 setvar 0
00021: 11 pop
;------------------------- 12: print("Enter another one: ");
00022: 12 name "print"
00025: 12 pushobj
00026: 12 string "Enter another one: "
00029: 12 call 1
00032: 12 pop
;------------------------- 13: var n2 = readline();
00033: 13 name "readline"
00036: 13 pushobj
00037: 13 call 0
00040: 13 setvar 1
00043: 13 pop
;------------------------- 14:
;------------------------- 15: print("You entered " + n1 + " and " + n2 + "\n");
00044: 15 name "print"
00047: 15 pushobj
00048: 15 string "You entered "
00051: 15 getvar 0
00054: 15 add
00055: 15 string " and "
00058: 15 add
00059: 15 getvar 1
00062: 15 add
00063: 15 string "\\n"
00066: 15 add
00067: 15 call 1
00070: 15 pop
00071: 15 stop
</pre>
<h4 id="evalcx.28string.5B.2C_object.5D.29" name="evalcx.28string.5B.2C_object.5D.29"><code>evalcx(<em>string[, object]</em> )</code></h4>
<p>Evaluates the JavaScript code in<em>string</em> . If<em>object</em> is specified, the code is executed in that object, treating it as a sandbox.</p>
<p>If<em>string</em> is empty and<em>object</em> is not specified, <code>evalcx()</code> returns a new object with eager standard classes.</p>
<p>If<em>string</em> is "lazy" and<em>object</em> is not specified, <code>evalcx()</code> returns a new object with lazy standard classes.</p>
<div class="note"><strong>Note:</strong> <code>evalcx()</code> is only useful for people doing deep internal work on the JavaScript engine, for testing <code>evalInSandbox</code>-like environments in the shell.</div>
<h4 id="gc.28.29" name="gc.28.29"><code>gc()</code></h4>
<p>가비지 콜렉터를 실행하여 메모리를 깨끗이 비웁니다.</p>
<h4 id="getpda.28object.29" name="getpda.28object.29"><code>getpda(<em>object</em> )</code></h4>
<p>Returns the property descriptors for the specified<em>object</em> .</p>
<h4 id="getslx.28object.29" name="getslx.28object.29"><code>getslx(<em>object</em> )</code></h4>
<p>Returns the script line extent, which is the number of lines of code comprising the specified object.</p>
<h4 id="help.28.5Bcommand_....5D.29" name="help.28.5Bcommand_....5D.29"><code>help(<em>[command ...]</em> )</code></h4>
<p>Displays brief help information about the specified commands, or about all available functions if none are specified.</p>
<h4 id="intern.28string.29" name="intern.28string.29"><code>intern(<em>string</em> )</code></h4>
<p>Internalizes the specified <var>string</var> into the atom table. Every string has a unique identifier, called an atom. This system makes it easier to do comparisons between strings.</p>
<div class="note"><strong>Note:</strong> This function is intended only for use when testing the JavaScript engine.</div>
<h4 id="line2pc.28.5Bfunction.2C_.5D_line.29" name="line2pc.28.5Bfunction.2C_.5D_line.29"><code>line2pc(<em>[function, ] line</em> )</code></h4>
<p>Returns the program counter value corresponding to the specified<em>line</em> of code. If<em>function</em> is specified,<em>line</em> is an offset into the specified function.</p>
<h4 id="load.28filename1_.5Bfilename.5D.29" name="load.28filename1_.5Bfilename.5D.29"><code>load(<em>filename1</em><em>[filename]</em> )</code></h4>
<p>Loads the files with the specified names.</p>
<h4 id="notes.28.5Bfunction.5D.29" name="notes.28.5Bfunction.5D.29"><code>notes(<em>[function]</em> )</code></h4>
<p>Shows the source notes for the specified function. Source notes contain information that map the bytecode to the source code, which is used when decompiling the code, such as when using the <code>dissrc()</code> function.</p>
<h4 id="options.28.5Boption_....5D.29" name="options.28.5Boption_....5D.29"><code>options(<em>[option ...]</em> )</code></h4>
<p>Lets you set or get options. If you specified options on the command line, the results of calling <code>options</code> will indicate which options you requested. You can also pass in new options to set.</p>
<p>If you start the shell with the command js -x, then the <code>options()</code> function will return xml. If you start the shell with no options, and decide you want to enable XML mode, you can do so by issuing the command:</p>
<pre class="eval">options('xml');
</pre>
<p>The available options are:</p>
<table class="standard-table">
<tbody>
<tr>
<td class="header">Option Name</td>
<td class="header">Description</td>
</tr>
<tr>
<td><code>strict</code></td>
<td>Strict 모드를 활성화합니다.</td>
</tr>
<tr>
<td><code>werror</code></td>
<td>경고를 에러로 속여 출력합니다.</td>
</tr>
<tr>
<td><code>atline</code></td>
<td>When <code>atline</code> is enabled, comments of the form <code>//@line<em>num</em> </code> set the number of the following line to <code><em>num</em> </code>.</td>
</tr>
<tr>
<td><code>xml</code></td>
<td>XML 모드를 활성화합니다.</td>
</tr>
</tbody>
</table>
<h4 id="pc2line.28function.2C_.5Bpc.5D.29" name="pc2line.28function.2C_.5Bpc.5D.29"><code>pc2line(<em>function, [pc]</em> )</code></h4>
<p>Returns the line number of the JavaScript code that corresponds to the first line of the specified<em>function</em> . If you specify a program counter offset into the function, the line number of the line of code containing that offset is returned.</p>
<h4 id="print.28.5Bexpression_....5D.29" name="print.28.5Bexpression_....5D.29"><code>print(<em>[expression ...]</em> )</code></h4>
<p>문자열이면 문자열, 식이면 식으로<em>expression</em> 의 값을 구하여 그 결과를 stdout 으로 출력합니다.</p>
<h4 id="quit.28.29" name="quit.28.29"><code>quit()</code></h4>
<p>셸에서 빠져나옵니다.</p>
<h4 id="readline.28.29" name="readline.28.29"><code>readline()</code></h4>
<p>표준 입력으로 읽어들여 호출자에게 되돌려줍니다. 이 함수를 사용하여 자바스크립트에서 인터랙티브 셸 프로그램을 만들 수 있습니다.</p>
<h4 id="seal.28object.5B.2C_deep.5D.29" name="seal.28object.5B.2C_deep.5D.29"><code>seal(<em>object[, deep]</em> )</code></h4>
<p>Seals the specified<em>object</em> , or an object graph if<em>deep</em> is <code>true</code>. By sealing an object or object graph, you disable modification of those objects.</p>
<h4 id="stats.28.5Bstring_....5D.29" name="stats.28.5Bstring_....5D.29"><code>stats(<em>[string ...]</em> )</code></h4>
<p>Dumps statistics. Valid options are<em>arena</em> ,<em>atom</em> , and<em>global</em> .</p>
<table class="standard-table">
<tbody>
<tr>
<td class="header">Option</td>
<td class="header">Description</td>
</tr>
<tr>
<td><code>arena</code></td>
<td>Outputs the arena table.</td>
</tr>
<tr>
<td><code>atom</code></td>
<td>Outputs the atom table.</td>
</tr>
<tr>
<td><code>global</code></td>
<td>Outputs the global name table.</td>
</tr>
</tbody>
</table>
<p>An<em>arena</em> is a large block of memory from which the JavaScript engine allocates sub-blocks in order to optimize performance; issuing a large number of <code>malloc()</code> calls for each individual block is inefficient, so the engine creates arenas, then uses an internal memory management system to allocate memory from within those. The arena table is a list of all the arenas that have been allocated by the shell. <code>stats("arena")</code> lets you inspect the arena table so that you can see how a test case uses arenas.</p>
<p>An<em>atom</em> is a unique identifier for a string. In order to optimize comparisons between strings, each string is given an atom. These atoms are stored in a hash table, which you can display using the command <code>stats("atom")</code>.</p>
<p><code>stats("global")</code> displays the global name table, which contains the names and information about each object in memory.</p>
<h4 id="stringsAreUtf8.28.29" name="stringsAreUtf8.28.29"><code>stringsAreUtf8()</code></h4>
<p>문자열이 UTF8 형식으로 인코드 되어있을 경우 <code>true</code>를, 그 외의 경우 <code>false</code>를 반환합니다.</p>
<h4 id="testUtf8.28mode.29" name="testUtf8.28mode.29"><code>testUtf8(<em>mode</em> )</code></h4>
<p>UTF-8이 제대로 동작하는지 1에서 4까지의 정수 변수를 입력하여 테스트합니다. 이것은 UTF-8 문자열이 제대로 처리되는지 확인하는 간단한 디버깅 명령으로, 일반적으로는 이 명령을 사용하여 따로 확인하기보다는 자바스크립트 엔진에서 직접 작업하며 확인하는 것이 빠릅니다.</p>
<h4 id="throwError.28.29" name="throwError.28.29"><code>throwError()</code></h4>
<p><code>JS_ReportError()</code> 함수에서 에러를 받아 지정된 방식으로 처리합니다.</p>
<div class="note"><strong>Note:</strong> 이 함수는 자바스크립트 엔진을 시험하는 목적으로만 사용하세요.</div>
<h4 id="tracing.28.5Btoggle.5D.29" name="tracing.28.5Btoggle.5D.29"><code>tracing(<em>[toggle]</em> )</code></h4>
<p><code>true</code> 혹은 <code>false</code>로 지정하여 트레이스 모드를 켜거나 끌 때 사용합니다. 따로 설정한 것이 없다면 <code>tracing()</code> 함수는 일반적인 설정사항을 반환할 것입니다.</p>
<div class="note"><strong>Tip:</strong> 이 함수는 자바스크립트를 <code> JS_THREADED_INTERP</code>로 빌드했을 때만 사용할 수 있습니다. 이 옵션은 jsinterp.c에서 지정할 수 있습니다.</div>
<h4 id="trap.28.5Bfunction.2C_.5Bpc.2C.5D.5D_expression.29" name="trap.28.5Bfunction.2C_.5Bpc.2C.5D.5D_expression.29"><code>trap(<em>[function, [pc,]] expression</em> )</code></h4>
<p>자바스크립트 코드의 지정된 위치에 트랩을 설정합니다. 해당<em>function</em> 의<em>pc</em> 오프셋에<em>expression</em> 에 해당하는 바이트 코드를 집어넣을 수 있습니다.</p>
<p><code>line2pc()</code>와 함께 사용하면 강력한 디버깅 방법이 됩니다 예를 들어 원래는 <code>doSomething()</code>을 사용하는 함수의 6번째 줄을 실행할 때 메시지를 출력하고 싶다면 다음과 같이 사용할 수 있습니다.</p>
<pre>trap(doSomething, line2pc(test, 6), "print('line 6!\n')");
</pre>
<div class="note"><strong>Note:</strong> 트랩이 설정된 동안 프로그램 내의 해당 바이트 코드는 <code>untrap()</code>을 사용하여 트랩을 해제할 때 까지 <code>trap</code> 바이트 코드로 대체됩니다.</div>
<h4 id="untrap.28function_.5B.2C_pc.5D.29" name="untrap.28function_.5B.2C_pc.5D.29"><code>untrap(<em>function [, pc]</em> )</code></h4>
<p>지정된<em>function</em> 의<em>pc</em> 오프셋에서 트랩을 삭제합니다.<em>pc</em> 가 지정되지 않았다면 해당 함수수에 접근할 때 걸리는 트랩을 삭제하게 됩니다. 이 함수는 트랩이 지정되지 않았을 경우에는 아무 동작도 하지 않습니다.</p>
<h4 id="version.28.5Bnumber.5D.29" name="version.28.5Bnumber.5D.29"><code>version(<em>[number]</em> )</code></h4>
<p><code>version()</code> 함수는 자바스크립트 버전을 반환합니다. 그다지 쓸 일이 있는 함수는 아니지요.</p>
|