Merge "fix: the incorrect version of tarball generated by gbs export" into tizen
[platform/upstream/js.git] / patches / bug-630209.patch
1 diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp
2 --- a/js/jsd/jsd_xpc.cpp
3 +++ b/js/jsd/jsd_xpc.cpp
4 @@ -1037,17 +1037,17 @@ PCMapEntry *
5  jsdScript::CreatePPLineMap()
6  {    
7      JSContext  *cx  = JSD_GetDefaultJSContext (mCx);
8      JSAutoRequest ar(cx);
9      JSObject   *obj = JS_NewObject(cx, NULL, NULL, NULL);
10      JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
11      JSScript   *script; /* In JSD compartment */
12      PRUint32    baseLine;
13 -    PRBool      scriptOwner = PR_FALSE;
14 +    JSObject   *scriptObj = NULL;
15      JSString   *jsstr;
16      size_t      length;
17      const jschar *chars;
18      
19      if (fun) {
20          uintN nargs;
21  
22          {
23 @@ -1075,36 +1075,40 @@ jsdScript::CreatePPLineMap()
24          if (!fun || !(script = JS_GetFunctionScript(cx, fun)))
25              return nsnull;
26          baseLine = 3;
27      } else {
28          script = JSD_GetJSScript(mCx, mScript);
29          JSString *jsstr;
30  
31          {
32 -            JSAutoEnterCompartment ac;
33 +            JS::AutoEnterScriptCompartment ac;
34              if (!ac.enter(cx, script))
35                  return nsnull;
36  
37 -            jsstr = JS_DecompileScript (cx, JSD_GetJSScript(mCx, mScript), "ppscript", 4);
38 +            jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
39              if (!jsstr)
40                  return nsnull;
41  
42              if (!(chars = JS_GetStringCharsAndLength(cx, jsstr, &length)))
43                  return nsnull;
44          }
45  
46          JS::Anchor<JSString *> kungFuDeathGrip(jsstr);
47 -        script = JS_CompileUCScript (cx, obj, chars, length, "x-jsd:ppbuffer?type=script", 1);
48 -        if (!script)
49 +        scriptObj = JS_CompileUCScript (cx, obj, chars, length, "x-jsd:ppbuffer?type=script", 1);
50 +        if (!scriptObj)
51              return nsnull;
52 -        scriptOwner = PR_TRUE;
53 +        script = JS_GetScriptFromObject(scriptObj);
54          baseLine = 1;
55      }
56  
57 +    /* Make sure that a non-function script is rooted via scriptObj until the
58 +     * end of script usage. */
59 +    JS::Anchor<JSObject *> scriptAnchor(scriptObj);
60 +
61      PRUint32 scriptExtent = JS_GetScriptLineExtent (cx, script);
62      jsbytecode* firstPC = JS_LineNumberToPC (cx, script, 0);
63      /* allocate worst case size of map (number of lines in script + 1
64       * for our 0 record), we'll shrink it with a realloc later. */
65      PCMapEntry *lineMap =
66          static_cast<PCMapEntry *>
67                     (PR_Malloc((scriptExtent + 1) * sizeof (PCMapEntry)));
68      PRUint32 lineMapSize = 0;
69 @@ -1125,19 +1129,16 @@ jsdScript::CreatePPLineMap()
70                                         lineMapSize * sizeof(PCMapEntry)));
71              if (!lineMap) {
72                  PR_Free(mPPLineMap);
73                  lineMapSize = 0;
74              }
75          }
76      }
77  
78 -    if (scriptOwner)
79 -        JS_DestroyScript (cx, script);
80 -
81      mPCMapSize = lineMapSize;
82      return mPPLineMap = lineMap;
83  }
84  
85  PRUint32
86  jsdScript::PPPcToLine (PRUint32 aPC)
87  {
88      if (!mPPLineMap && !CreatePPLineMap())
89 @@ -1182,17 +1183,17 @@ jsdScript::GetJSDScript(JSDScript **_rva
90  }
91  
92  NS_IMETHODIMP
93  jsdScript::GetVersion (PRInt32 *_rval)
94  {
95      ASSERT_VALID_EPHEMERAL;
96      JSContext *cx = JSD_GetDefaultJSContext (mCx);
97      JSScript *script = JSD_GetJSScript(mCx, mScript);
98 -    JSAutoEnterCompartment ac;
99 +    JS::AutoEnterScriptCompartment ac;
100      if (!ac.enter(cx, script))
101          return NS_ERROR_FAILURE;
102      *_rval = static_cast<PRInt32>(JS_GetScriptVersion(cx, script));
103      return NS_OK;
104  }
105  
106  NS_IMETHODIMP
107  jsdScript::GetTag(PRUint32 *_rval)
108 @@ -1378,23 +1379,24 @@ jsdScript::GetFunctionSource(nsAString &
109          return NS_ERROR_FAILURE;
110      }
111      JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
112  
113      JSAutoRequest ar(cx);
114  
115      JSString *jsstr;
116      JSAutoEnterCompartment ac;
117 +    JS::AutoEnterScriptCompartment asc;
118      if (fun) {
119          if (!ac.enter(cx, JS_GetFunctionObject(fun)))
120              return NS_ERROR_FAILURE;
121          jsstr = JS_DecompileFunction (cx, fun, 4);
122      } else {
123          JSScript *script = JSD_GetJSScript (mCx, mScript);
124 -        if (!ac.enter(cx, script))
125 +        if (!asc.enter(cx, script))
126              return NS_ERROR_FAILURE;
127          jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
128      }
129      if (!jsstr)
130          return NS_ERROR_FAILURE;
131  
132      size_t length;
133      const jschar *chars = JS_GetStringCharsZAndLength(cx, jsstr, &length);
134 diff --git a/js/src/jsapi-tests/testScriptObject.cpp b/js/src/jsapi-tests/testScriptObject.cpp
135 --- a/js/src/jsapi-tests/testScriptObject.cpp
136 +++ b/js/src/jsapi-tests/testScriptObject.cpp
137 @@ -10,41 +10,25 @@ struct ScriptObjectFixture : public JSAP
138      static jschar uc_code[];
139  
140      ScriptObjectFixture()
141      {
142          for (int i = 0; i < code_size; i++)
143              uc_code[i] = code[i];
144      }
145  
146 -    bool tryScript(JSScript *script)
147 +    bool tryScript(JSObject *scriptObj)
148      {
149 -        CHECK(script);
150 -
151 -        /* We should have allocated a script object for the script already. */
152 -        jsvalRoot script_object(cx, OBJECT_TO_JSVAL(JS_GetScriptObject(script)));
153 -        CHECK(JSVAL_TO_OBJECT(script_object.value()));
154 -
155 -        /*
156 -         * JS_NewScriptObject just returns the object already created for the
157 -         * script. It was always a bug to call this more than once.
158 -         */
159 -        jsvalRoot second_script_object
160 -            (cx, OBJECT_TO_JSVAL(JS_NewScriptObject(cx, script)));
161 -        CHECK_SAME(second_script_object.value(), script_object.value());
162 +        CHECK(scriptObj);
163  
164          JS_GC(cx);
165  
166          /* After a garbage collection, the script should still work. */
167          jsval result;
168 -        CHECK(JS_ExecuteScript(cx, global, script, &result));
169 -
170 -        /* JS_DestroyScript must still be safe to call, whether or not it
171 -           actually has any effect. */
172 -        JS_DestroyScript(cx, script);
173 +        CHECK(JS_ExecuteScript(cx, global, scriptObj, &result));
174  
175          return true;
176      }
177  };
178  
179  const char ScriptObjectFixture::code[] =
180      "(function(a, b){return a+' '+b;}('hello', 'world'))";
181  const int ScriptObjectFixture::code_size = sizeof(ScriptObjectFixture::code) - 1;
182 @@ -98,31 +82,31 @@ END_FIXTURE_TEST(ScriptObjectFixture, bu
183  
184  BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
185  {
186      TempFile tempScript;
187      static const char script_filename[] = "temp-bug438633_JS_CompileFile";
188      FILE *script_stream = tempScript.open(script_filename);
189      CHECK(fputs(code, script_stream) != EOF);
190      tempScript.close();
191 -    JSScript *script = JS_CompileFile(cx, global, script_filename);
192 +    JSObject *scriptObj = JS_CompileFile(cx, global, script_filename);
193      tempScript.remove();
194 -    return tryScript(script);
195 +    return tryScript(scriptObj);
196  }
197  END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
198  
199  BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
200  {
201      TempFile tempScript;
202      static const char script_filename[] = "temp-bug438633_JS_CompileFile_empty";
203      tempScript.open(script_filename);
204      tempScript.close();
205 -    JSScript *script = JS_CompileFile(cx, global, script_filename);
206 +    JSObject *scriptObj = JS_CompileFile(cx, global, script_filename);
207      tempScript.remove();
208 -    return tryScript(script);
209 +    return tryScript(scriptObj);
210  }
211  END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
212  
213  BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
214  {
215      TempFile tempScript;
216      FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandle");
217      CHECK(fputs(code, script_stream) != EOF);
218 @@ -147,24 +131,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, 
219      FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandleForPrincipals");
220      CHECK(fputs(code, script_stream) != EOF);
221      CHECK(fseek(script_stream, 0, SEEK_SET) != EOF);
222      return tryScript(JS_CompileFileHandleForPrincipals(cx, global,
223                                                         "temporary file",
224                                                         script_stream, NULL));
225  }
226  END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals)
227 -
228 -BEGIN_TEST(testScriptObject_ScriptlessScriptObjects)
229 -{
230 -    /* JS_NewScriptObject(cx, NULL) should return a fresh object each time. */
231 -    jsvalRoot script_object1(cx, OBJECT_TO_JSVAL(JS_NewScriptObject(cx, NULL)));
232 -    CHECK(!JSVAL_IS_PRIMITIVE(script_object1.value()));
233 -
234 -    jsvalRoot script_object2(cx, OBJECT_TO_JSVAL(JS_NewScriptObject(cx, NULL)));
235 -    CHECK(!JSVAL_IS_PRIMITIVE(script_object2.value()));
236 -
237 -    if (script_object1.value() == script_object2.value())
238 -        return false;
239 -
240 -    return true;
241 -}
242 -END_TEST(testScriptObject_ScriptlessScriptObjects)
243 diff --git a/js/src/jsapi-tests/testTrap.cpp b/js/src/jsapi-tests/testTrap.cpp
244 --- a/js/src/jsapi-tests/testTrap.cpp
245 +++ b/js/src/jsapi-tests/testTrap.cpp
246 @@ -25,52 +25,56 @@ BEGIN_TEST(testTrap_gc)
247  "while (i < 10) {\n"
248  "    sum += i;\n"
249  "    ++i;\n"
250  "}\n"
251  "({ result: sum });\n"
252          ;
253  
254      // compile
255 -    JSScript *script = JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1);
256 -    CHECK(script);
257 -    JSObject *scrobj = JS_NewScriptObject(cx, script);
258 -    CHECK(scrobj);
259 -    jsvalRoot v(cx, OBJECT_TO_JSVAL(scrobj));
260 +    JSObject *scriptObj = JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1);
261 +    CHECK(scriptObj);
262  
263      // execute
264      jsvalRoot v2(cx);
265 -    CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
266 +    CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
267      CHECK(JSVAL_IS_OBJECT(v2));
268      CHECK(emptyTrapCallCount == 0);
269  
270      // Disable JIT for debugging
271      JS_SetOptions(cx, JS_GetOptions(cx) & ~JSOPTION_JIT);
272  
273      // Enable debug mode
274      CHECK(JS_SetDebugMode(cx, JS_TRUE));
275  
276 -    jsbytecode *line2 = JS_LineNumberToPC(cx, script, 1);
277 -    CHECK(line2);
278 +    static const char trapClosureText[] = "some trap closure";
279  
280 -    jsbytecode *line6 = JS_LineNumberToPC(cx, script, 5);
281 -    CHECK(line2);
282 -
283 -    static const char trapClosureText[] = "some trap closure";
284 -    JSString *trapClosure = JS_NewStringCopyZ(cx, trapClosureText);
285 -    CHECK(trapClosure);
286 -    JS_SetTrap(cx, script, line2, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
287 -    JS_SetTrap(cx, script, line6, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
288 -
289 -    JS_GC(cx);
290 -
291 -    CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(trapClosure), trapClosureText));
292 +    // scope JSScript  usage to make sure that it is not used after
293 +    // JS_ExecuteScript. This way we avoid using Anchor.
294 +    JSString *trapClosure;
295 +    {
296 +        JSScript *script = JS_GetScriptFromObject(scriptObj);
297 +        jsbytecode *line2 = JS_LineNumberToPC(cx, script, 1);
298 +        CHECK(line2);
299 +        
300 +        jsbytecode *line6 = JS_LineNumberToPC(cx, script, 5);
301 +        CHECK(line2);
302 +        
303 +        trapClosure = JS_NewStringCopyZ(cx, trapClosureText);
304 +        CHECK(trapClosure);
305 +        JS_SetTrap(cx, script, line2, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
306 +        JS_SetTrap(cx, script, line6, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
307 +        
308 +        JS_GC(cx);
309 +        
310 +        CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(trapClosure), trapClosureText));
311 +    }
312  
313      // execute
314 -    CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
315 +    CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
316      CHECK(emptyTrapCallCount == 11);
317  
318      JS_GC(cx);
319  
320      CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(trapClosure), trapClosureText));
321  
322      return true;
323  }
324 diff --git a/js/src/jsapi-tests/testVersion.cpp b/js/src/jsapi-tests/testVersion.cpp
325 --- a/js/src/jsapi-tests/testVersion.cpp
326 +++ b/js/src/jsapi-tests/testVersion.cpp
327 @@ -36,17 +36,17 @@ struct VersionFixture : public JSAPITest
328                 JS_DefineFunction(cx, global, "checkNewScriptNoXML", CheckNewScriptNoXML, 0, 0) &&
329                 JS_DefineFunction(cx, global, "overrideVersion15", OverrideVersion15, 0, 0) &&
330                 JS_DefineFunction(cx, global, "captureVersion", CaptureVersion, 0, 0) &&
331                 JS_DefineFunction(cx, global, "checkOverride", CheckOverride, 1, 0) &&
332                 JS_DefineFunction(cx, global, "evalScriptVersion16",
333                                   EvalScriptVersion16, 0, 0);
334      }
335  
336 -    JSScript *fakeScript(const char *contents, size_t length) {
337 +    JSObject *fakeScript(const char *contents, size_t length) {
338          return JS_CompileScript(cx, global, contents, length, "<test>", 1);
339      }
340  
341      bool hasXML(uintN version) {
342          return VersionHasXML(JSVersion(version));
343      }
344  
345      bool hasXML(JSScript *script) {
346 @@ -69,19 +69,19 @@ struct VersionFixture : public JSAPITest
347  
348      bool checkVersionIsOverridden() {
349          CHECK(cx->isVersionOverridden());
350          return true;
351      }
352  
353      /* Check that script compilation results in a version without XML. */
354      bool checkNewScriptNoXML() {
355 -        JSScript *script = fakeScript("", 0);
356 -        CHECK(script);
357 -        CHECK(!hasXML(script->getVersion()));
358 +        JSObject *scriptObj = fakeScript("", 0);
359 +        CHECK(scriptObj);
360 +        CHECK(!hasXML(JS_GetScriptFromObject(scriptObj)->getVersion()));
361          return true;
362      }
363  
364      bool checkVersionHasXML() {
365          CHECK(VersionHasXML(cx->findVersion()));
366          return true;
367      }
368  
369 @@ -190,25 +190,22 @@ BEGIN_FIXTURE_TEST(VersionFixture, testO
370  
371      /* Enable XML and compile a script to activate. */
372      enableXML();
373      const char toActivateChars[] =
374          "checkVersionHasXML();"
375          "disableXMLOption();"
376          "callSetVersion17();"
377          "checkNewScriptNoXML();";
378 -    JSScript *toActivate = fakeScript(toActivateChars, sizeof(toActivateChars) - 1);
379 +    JSObject *toActivate = fakeScript(toActivateChars, sizeof(toActivateChars) - 1);
380      CHECK(toActivate);
381 -    JSObject *scriptObject = JS_GetScriptObject(toActivate);
382 -    CHECK(hasXML(toActivate));
383 +    CHECK(hasXML(JS_GetScriptFromObject(toActivate)));
384  
385      disableXML();
386  
387 -    CHECK(scriptObject);
388 -
389      /* Activate the script. */
390      jsval dummy;
391      CHECK(JS_ExecuteScript(cx, global, toActivate, &dummy));
392      return true;
393  }
394  END_FIXTURE_TEST(VersionFixture, testOptionsAreUsedForVersionFlags)
395  
396  /*
397 diff --git a/js/src/jsapi-tests/testXDR.cpp b/js/src/jsapi-tests/testXDR.cpp
398 --- a/js/src/jsapi-tests/testXDR.cpp
399 +++ b/js/src/jsapi-tests/testXDR.cpp
400 @@ -11,87 +11,75 @@ BEGIN_TEST(testXDR_bug506491)
401      const char *s =
402          "function makeClosure(s, name, value) {\n"
403          "    eval(s);\n"
404          "    return let (n = name, v = value) function () { return String(v); };\n"
405          "}\n"
406          "var f = makeClosure('0;', 'status', 'ok');\n";
407  
408      // compile
409 -    JSScript *script = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
410 -    CHECK(script);
411 -    JSObject *scrobj = JS_NewScriptObject(cx, script);
412 -    CHECK(scrobj);
413 -    jsvalRoot v(cx, OBJECT_TO_JSVAL(scrobj));
414 +    JSObject *scriptObj = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
415 +    CHECK(scriptObj);
416  
417      // freeze
418      JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
419      CHECK(w);
420 -    CHECK(JS_XDRScript(w, &script));
421 +    CHECK(JS_XDRScriptObject(w, &scriptObj));
422      uint32 nbytes;
423      void *p = JS_XDRMemGetData(w, &nbytes);
424      CHECK(p);
425      void *frozen = JS_malloc(cx, nbytes);
426      CHECK(frozen);
427      memcpy(frozen, p, nbytes);
428      JS_XDRDestroy(w);
429  
430      // thaw
431 -    script = NULL;
432 +    scriptObj = NULL;
433      JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
434      JS_XDRMemSetData(r, frozen, nbytes);
435 -    CHECK(JS_XDRScript(r, &script));
436 +    CHECK(JS_XDRScriptObject(r, &scriptObj));
437      JS_XDRDestroy(r);  // this frees `frozen`
438 -    scrobj = JS_NewScriptObject(cx, script);
439 -    CHECK(scrobj);
440 -    v = OBJECT_TO_JSVAL(scrobj);
441  
442      // execute
443      jsvalRoot v2(cx);
444 -    CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
445 +    CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
446  
447      // try to break the Block object that is the parent of f
448      JS_GC(cx);
449  
450      // confirm
451      EVAL("f() === 'ok';\n", v2.addr());
452      jsvalRoot trueval(cx, JSVAL_TRUE);
453      CHECK_SAME(v2, trueval);
454      return true;
455  }
456  END_TEST(testXDR_bug506491)
457  
458  BEGIN_TEST(testXDR_bug516827)
459  {
460      // compile an empty script
461 -    JSScript *script = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
462 -    CHECK(script);
463 -    JSObject *scrobj = JS_NewScriptObject(cx, script);
464 -    CHECK(scrobj);
465 -    jsvalRoot v(cx, OBJECT_TO_JSVAL(scrobj));
466 +    JSObject *scriptObj = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
467 +    CHECK(scriptObj);
468  
469      // freeze
470      JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
471      CHECK(w);
472 -    CHECK(JS_XDRScript(w, &script));
473 +    CHECK(JS_XDRScriptObject(w, &scriptObj));
474      uint32 nbytes;
475      void *p = JS_XDRMemGetData(w, &nbytes);
476      CHECK(p);
477      void *frozen = JS_malloc(cx, nbytes);
478      CHECK(frozen);
479      memcpy(frozen, p, nbytes);
480      JS_XDRDestroy(w);
481  
482      // thaw
483 -    script = NULL;
484 +    scriptObj = NULL;
485      JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
486      JS_XDRMemSetData(r, frozen, nbytes);
487 -    CHECK(JS_XDRScript(r, &script));
488 +    CHECK(JS_XDRScriptObject(r, &scriptObj));
489      JS_XDRDestroy(r);  // this frees `frozen`
490 -    scrobj = JS_NewScriptObject(cx, script);
491 -    CHECK(scrobj);
492 -    v = OBJECT_TO_JSVAL(scrobj);
493  
494      // execute with null result meaning no result wanted
495 -    CHECK(JS_ExecuteScript(cx, global, script, NULL));
496 +    CHECK(JS_ExecuteScript(cx, global, scriptObj, NULL));
497      return true;
498  }
499  END_TEST(testXDR_bug516827)
500 diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp
501 --- a/js/src/jsapi.cpp
502 +++ b/js/src/jsapi.cpp
503 @@ -77,17 +77,16 @@
504  #include "jsparse.h"
505  #include "jsproxy.h"
506  #include "jsregexp.h"
507  #include "jsscan.h"
508  #include "jsscope.h"
509  #include "jsscript.h"
510  #include "jsstr.h"
511  #include "jstracer.h"
512 -#include "jsdbgapi.h"
513  #include "prmjtime.h"
514  #include "jsstaticcheck.h"
515  #include "jsvector.h"
516  #include "jswrapper.h"
517  #include "jstypedarray.h"
518  
519  #include "jsatominlines.h"
520  #include "jscntxtinlines.h"
521 @@ -107,26 +106,16 @@
522  
523  #if JS_HAS_XML_SUPPORT
524  #include "jsxml.h"
525  #endif
526  
527  using namespace js;
528  using namespace js::gc;
529  
530 -static JSClass dummy_class = {
531 -    "jdummy",
532 -    JSCLASS_GLOBAL_FLAGS,
533 -    JS_PropertyStub,  JS_PropertyStub,
534 -    JS_PropertyStub,  JS_StrictPropertyStub,
535 -    JS_EnumerateStub, JS_ResolveStub,
536 -    JS_ConvertStub,   NULL,
537 -    JSCLASS_NO_OPTIONAL_MEMBERS
538 -};
539 -
540  /*
541   * This class is a version-establising barrier at the head of a VM entry or
542   * re-entry. It ensures that:
543   *
544   * - |newVersion| is the starting (default) version used for the context.
545   * - The starting version state is not an override.
546   * - Overrides in the VM session are not propagated to the caller.
547   */
548 @@ -1187,16 +1176,26 @@ JS_EnterCrossCompartmentCall(JSContext *
549          return NULL;
550      }
551      return reinterpret_cast<JSCrossCompartmentCall *>(call);
552  }
553  
554  JS_PUBLIC_API(JSCrossCompartmentCall *)
555  JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target)
556  {
557 +    static JSClass dummy_class = {
558 +        "jdummy",
559 +        JSCLASS_GLOBAL_FLAGS,
560 +        JS_PropertyStub,  JS_PropertyStub,
561 +        JS_PropertyStub,  JS_StrictPropertyStub,
562 +        JS_EnumerateStub, JS_ResolveStub,
563 +        JS_ConvertStub,   NULL,
564 +        JSCLASS_NO_OPTIONAL_MEMBERS
565 +    };
566 +
567      CHECK_REQUEST(cx);
568  
569      JS_ASSERT(target);
570      JSObject *scriptObject = target->u.object;
571      if (!scriptObject) {
572          SwitchToCompartment sc(cx, target->compartment);
573          scriptObject = JS_NewGlobalObject(cx, &dummy_class);
574          if (!scriptObject)
575 @@ -1221,33 +1220,37 @@ JSAutoEnterCompartment::enter(JSContext 
576      if (cx->compartment == target->getCompartment()) {
577          call = reinterpret_cast<JSCrossCompartmentCall*>(1);
578          return true;
579      }
580      call = JS_EnterCrossCompartmentCall(cx, target);
581      return call != NULL;
582  }
583  
584 +void
585 +JSAutoEnterCompartment::enterAndIgnoreErrors(JSContext *cx, JSObject *target)
586 +{
587 +    (void) enter(cx, target);
588 +}
589 +
590 +namespace JS {
591 +
592  bool
593 -JSAutoEnterCompartment::enter(JSContext *cx, JSScript *target)
594 +AutoEnterScriptCompartment::enter(JSContext *cx, JSScript *target)
595  {
596      JS_ASSERT(!call);
597      if (cx->compartment == target->compartment) {
598          call = reinterpret_cast<JSCrossCompartmentCall*>(1);
599          return true;
600      }
601      call = JS_EnterCrossCompartmentCallScript(cx, target);
602      return call != NULL;    
603  }
604  
605 -void
606 -JSAutoEnterCompartment::enterAndIgnoreErrors(JSContext *cx, JSObject *target)
607 -{
608 -    (void) enter(cx, target);
609 -}
610 +} /* namespace JS */
611  
612  JS_PUBLIC_API(void *)
613  JS_SetCompartmentPrivate(JSContext *cx, JSCompartment *compartment, void *data)
614  {
615      CHECK_REQUEST(cx);
616      void *old = compartment->data;
617      compartment->data = data;
618      return old;
619 @@ -2181,16 +2184,21 @@ JS_RemoveObjectRoot(JSContext *cx, JSObj
620  
621  JS_PUBLIC_API(JSBool)
622  JS_RemoveGCThingRoot(JSContext *cx, void **rp)
623  {
624      CHECK_REQUEST(cx);
625      return js_RemoveRoot(cx->runtime, (void *)rp);
626  }
627  
628 +JS_NEVER_INLINE JS_PUBLIC_API(void)
629 +JS_AnchorPtr(void *p)
630 +{
631 +}
632 +
633  #ifdef DEBUG
634  
635  JS_PUBLIC_API(void)
636  JS_DumpNamedRoots(JSRuntime *rt,
637                    void (*dump)(const char *name, void *rp, JSGCRootType type, void *data),
638                    void *data)
639  {
640      js_DumpNamedRoots(rt, dump, data);
641 @@ -4510,94 +4518,97 @@ LAST_FRAME_CHECKS(JSContext *cx, bool re
642  
643  inline static uint32
644  JS_OPTIONS_TO_TCFLAGS(JSContext *cx)
645  {
646      return (cx->hasRunOption(JSOPTION_COMPILE_N_GO) ? TCF_COMPILE_N_GO : 0) |
647             (cx->hasRunOption(JSOPTION_NO_SCRIPT_RVAL) ? TCF_NO_SCRIPT_RVAL : 0);
648  }
649  
650 -static JSScript *
651 +static JSObject *
652  CompileUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj, JSPrincipals *principals,
653                                        const jschar *chars, size_t length,
654                                        const char *filename, uintN lineno, JSVersion version)
655  {
656      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
657      CHECK_REQUEST(cx);
658      assertSameCompartment(cx, obj, principals);
659  
660      uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
661      JSScript *script = Compiler::compileScript(cx, obj, NULL, principals, tcflags,
662                                                 chars, length, filename, lineno, version);
663 -    if (script && !js_NewScriptObject(cx, script)) {
664 -        js_DestroyScript(cx, script);
665 -        script = NULL;
666 +    JSObject *scriptObj = NULL;
667 +    if (script) {
668 +        scriptObj = js_NewScriptObject(cx, script);
669 +        if (!scriptObj)
670 +            js_DestroyScript(cx, script);
671      }
672 -    LAST_FRAME_CHECKS(cx, script);
673 -    return script;
674 -}
675 -
676 -extern JS_PUBLIC_API(JSScript *)
677 +    LAST_FRAME_CHECKS(cx, scriptObj);
678 +    return scriptObj;
679 +}
680 +
681 +extern JS_PUBLIC_API(JSObject *)
682  JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
683                                         JSPrincipals *principals,
684                                         const jschar *chars, size_t length,
685                                         const char *filename, uintN lineno,
686                                         JSVersion version)
687  {
688      AutoVersionAPI avi(cx, version);
689      return CompileUCScriptForPrincipalsCommon(cx, obj, principals, chars, length, filename, lineno,
690                                                avi.version());
691  }
692  
693 -JS_PUBLIC_API(JSScript *)
694 +JS_PUBLIC_API(JSObject *)
695  JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, JSPrincipals *principals,
696                                  const jschar *chars, size_t length,
697                                  const char *filename, uintN lineno)
698  {
699      return CompileUCScriptForPrincipalsCommon(cx, obj, principals, chars, length, filename, lineno,
700                                                cx->findVersion());
701  }
702  
703 -JS_PUBLIC_API(JSScript *)
704 +JS_PUBLIC_API(JSObject *)
705  JS_CompileUCScript(JSContext *cx, JSObject *obj, const jschar *chars, size_t length,
706                     const char *filename, uintN lineno)
707  {
708      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
709      return JS_CompileUCScriptForPrincipals(cx, obj, NULL, chars, length, filename, lineno);
710  }
711  
712 -JS_PUBLIC_API(JSScript *)
713 +JS_PUBLIC_API(JSObject *)
714  JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
715                                       JSPrincipals *principals,
716                                       const char *bytes, size_t length,
717                                       const char *filename, uintN lineno,
718                                       JSVersion version)
719  {
720      AutoVersionAPI ava(cx, version);
721      return JS_CompileScriptForPrincipals(cx, obj, principals, bytes, length, filename, lineno);
722  }
723  
724 -JS_PUBLIC_API(JSScript *)
725 +JS_PUBLIC_API(JSObject *)
726  JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
727                                JSPrincipals *principals,
728                                const char *bytes, size_t length,
729                                const char *filename, uintN lineno)
730  {
731      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
732      CHECK_REQUEST(cx);
733  
734      jschar *chars = js_InflateString(cx, bytes, &length);
735      if (!chars)
736          return NULL;
737 -    JSScript *script = JS_CompileUCScriptForPrincipals(cx, obj, principals, chars, length, filename, lineno);
738 +    JSObject *scriptObj =
739 +        JS_CompileUCScriptForPrincipals(cx, obj, principals, chars, length, filename, lineno);
740      cx->free(chars);
741 -    return script;
742 -}
743 -
744 -JS_PUBLIC_API(JSScript *)
745 +    return scriptObj;
746 +}
747 +
748 +JS_PUBLIC_API(JSObject *)
749  JS_CompileScript(JSContext *cx, JSObject *obj, const char *bytes, size_t length,
750                   const char *filename, uintN lineno)
751  {
752      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
753      return JS_CompileScriptForPrincipals(cx, obj, NULL, bytes, length, filename, lineno);
754  }
755  
756  JS_PUBLIC_API(JSBool)
757 @@ -4645,18 +4656,18 @@ JS_BufferIsCompilableUnit(JSContext *cx,
758  #if defined(HAVE_GETC_UNLOCKED)
759  # define fast_getc getc_unlocked
760  #elif defined(HAVE__GETC_NOLOCK)
761  # define fast_getc _getc_nolock
762  #else
763  # define fast_getc getc
764  #endif
765  
766 -static JSScript *
767 -CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals, uint32 tcflags,
768 +static JSObject *
769 +CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals,
770                    const char* filename, FILE *fp)
771  {
772      struct stat st;
773      int ok = fstat(fileno(fp), &st);
774      if (ok != 0)
775          return NULL;
776  
777      jschar *buf = NULL;
778 @@ -4667,165 +4678,122 @@ CompileFileHelper(JSContext *cx, JSObjec
779      /* Read in the whole file, then compile it. */
780      if (fp == stdin) {
781          JS_ASSERT(len == 0);
782          len = 8;  /* start with a small buffer, expand as necessary */
783          int c;
784          bool hitEOF = false;
785          while (!hitEOF) {
786              len *= 2;
787 -            jschar* tmpbuf = (jschar *) cx->realloc(buf, len * sizeof(jschar));
788 +            jschar* tmpbuf = (jschar *) js_realloc(buf, len * sizeof(jschar));
789              if (!tmpbuf) {
790                  cx->free(buf);
791                  return NULL;
792              }
793              buf = tmpbuf;
794  
795              while (i < len) {
796                  c = fast_getc(fp);
797                  if (c == EOF) {
798                      hitEOF = true;
799                      break;
800                  }
801                  buf[i++] = (jschar) (unsigned char) c;
802              }
803          }
804      } else {
805 -        buf = (jschar *) cx->malloc(len * sizeof(jschar));
806 +        buf = (jschar *) js_malloc(len * sizeof(jschar));
807          if (!buf)
808              return NULL;
809  
810          int c;
811          while ((c = fast_getc(fp)) != EOF)
812              buf[i++] = (jschar) (unsigned char) c;
813      }
814  
815      JS_ASSERT(i <= len);
816      len = i;
817 +    uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
818      script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, buf, len, filename, 1,
819                                       cx->findVersion());
820 -    cx->free(buf);
821 -    return script;
822 -}
823 -
824 -JS_PUBLIC_API(JSScript *)
825 +    js_free(buf);
826 +    if (!script)
827 +        return NULL;
828 +
829 +    JSObject *scriptObj = js_NewScriptObject(cx, script);
830 +    if (!scriptObj)
831 +        js_DestroyScript(cx, script);
832 +    
833 +    return scriptObj;
834 +}
835 +
836 +JS_PUBLIC_API(JSObject *)
837  JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
838  {
839      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
840 -    FILE *fp;
841 -    uint32 tcflags;
842 -    JSScript *script;
843  
844      CHECK_REQUEST(cx);
845      assertSameCompartment(cx, obj);
846 -    if (!filename || strcmp(filename, "-") == 0) {
847 -        fp = stdin;
848 -    } else {
849 -        fp = fopen(filename, "r");
850 -        if (!fp) {
851 -            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_OPEN,
852 -                                 filename, "No such file or directory");
853 -            return NULL;
854 +    JSObject *scriptObj = NULL;
855 +    do {
856 +        FILE *fp;
857 +        if (!filename || strcmp(filename, "-") == 0) {
858 +            fp = stdin;
859 +        } else {
860 +            fp = fopen(filename, "r");
861 +            if (!fp) {
862 +                JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_OPEN,
863 +                                     filename, "No such file or directory");
864 +                break;
865 +            }
866          }
867 -    }
868 -
869 -    tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
870 -    script = CompileFileHelper(cx, obj, NULL, tcflags, filename, fp);
871 -
872 -    if (fp != stdin)
873 -        fclose(fp);
874 -    if (script && !js_NewScriptObject(cx, script)) {
875 -        js_DestroyScript(cx, script);
876 -        script = NULL;
877 -    }
878 -    LAST_FRAME_CHECKS(cx, script);
879 -    return script;
880 -}
881 -
882 -JS_PUBLIC_API(JSScript *)
883 -JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
884 -                                  JSPrincipals *principals)
885 +
886 +        scriptObj = CompileFileHelper(cx, obj, NULL, filename, fp);
887 +        if (fp != stdin)
888 +            fclose(fp);
889 +    } while (false);
890 +    
891 +    LAST_FRAME_CHECKS(cx, scriptObj);
892 +    return scriptObj;
893 +}
894 +
895 +JS_PUBLIC_API(JSObject *)
896 +JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *filename,
897 +                                  FILE *file, JSPrincipals *principals)
898  {
899      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
900 -    uint32 tcflags;
901 -    JSScript *script;
902  
903      CHECK_REQUEST(cx);
904      assertSameCompartment(cx, obj, principals);
905 -    tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
906 -    script = CompileFileHelper(cx, obj, principals, tcflags, filename, file);
907 -
908 -    if (script && !js_NewScriptObject(cx, script)) {
909 -        js_DestroyScript(cx, script);
910 -        script = NULL;
911 -    }
912 -    LAST_FRAME_CHECKS(cx, script);
913 -    return script;
914 -}
915 -
916 -JS_PUBLIC_API(JSScript *)
917 +    JSObject *scriptObj = CompileFileHelper(cx, obj, principals, filename, file);
918 +    LAST_FRAME_CHECKS(cx, scriptObj);
919 +    return scriptObj;
920 +}
921 +
922 +JS_PUBLIC_API(JSObject *)
923  JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj, const char *filename,
924                                           FILE *file, JSPrincipals *principals, JSVersion version)
925  {
926      AutoVersionAPI ava(cx, version);
927      return JS_CompileFileHandleForPrincipals(cx, obj, filename, file, principals);
928  }
929  
930 -JS_PUBLIC_API(JSScript *)
931 +JS_PUBLIC_API(JSObject *)
932  JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename, FILE *file)
933  {
934      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
935      return JS_CompileFileHandleForPrincipals(cx, obj, filename, file, NULL);
936  }
937  
938 -JS_PUBLIC_API(JSObject *)
939 -JS_NewScriptObject(JSContext *cx, JSScript *script)
940 -{
941 -    JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
942 -    CHECK_REQUEST(cx);
943 -    assertSameCompartment(cx, script);
944 -    if (!script)
945 -        return NewNonFunction<WithProto::Class>(cx, &js_ScriptClass, NULL, NULL);
946 -
947 -    /*
948 -     * This function should only ever be applied to JSScripts that had
949 -     * script objects allocated for them when they were created, as
950 -     * described in the comment for JSScript::u.object.
951 -     */
952 -    JS_ASSERT(script->u.object);
953 -    return script->u.object;
954 -}
955 -
956 -JS_PUBLIC_API(JSObject *)
957 -JS_GetScriptObject(JSScript *script)
958 -{
959 -    /*
960 -     * This function should only ever be applied to JSScripts that had
961 -     * script objects allocated for them when they were created, as
962 -     * described in the comment for JSScript::u.object.
963 -     */
964 -    JS_ASSERT(script->u.object);
965 -    return script->u.object;
966 -}
967 -
968 -JS_PUBLIC_API(void)
969 -JS_DestroyScript(JSContext *cx, JSScript *script)
970 -{
971 -    CHECK_REQUEST(cx);
972 -
973 -    /*
974 -     * Originally, JSScript lifetimes were managed explicitly, and this function
975 -     * was used to free a JSScript. Now, this function does nothing, and the
976 -     * garbage collector manages JSScripts; you must root the JSScript's script
977 -     * object (obtained via JS_GetScriptObject) to keep it alive.
978 -     *
979 -     * However, since the script objects have taken over this responsibility, it
980 -     * follows that every script passed here must have a script object.
981 -     */
982 -    JS_ASSERT(script->u.object);
983 +JS_PUBLIC_API(JSScript *)
984 +JS_GetScriptFromObject(JSObject *scriptObj)
985 +{
986 +    JS_ASSERT(scriptObj->isScript());
987 +
988 +    return (JSScript *) scriptObj->getPrivate();
989  }
990  
991  static JSFunction *
992  CompileUCFunctionForPrincipalsCommon(JSContext *cx, JSObject *obj,
993                                       JSPrincipals *principals, const char *name,
994                                       uintN nargs, const char **argnames,
995                                       const jschar *chars, size_t length,
996                                       const char *filename, uintN lineno, JSVersion version)
997 @@ -4985,16 +4953,22 @@ JS_DecompileScript(JSContext *cx, JSScri
998          str = js_GetPrinterOutput(jp);
999      else
1000          str = NULL;
1001      js_DestroyPrinter(jp);
1002      return str;
1003  }
1004  
1005  JS_PUBLIC_API(JSString *)
1006 +JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent)
1007 +{
1008 +    return JS_DecompileScript(cx, scriptObj->getScript(), name, indent);
1009 +}
1010 +
1011 +JS_PUBLIC_API(JSString *)
1012  JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent)
1013  {
1014      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
1015      CHECK_REQUEST(cx);
1016      assertSameCompartment(cx, fun);
1017      return js_DecompileToString(cx, "JS_DecompileFunction", fun,
1018                                  indent & ~JS_DONT_PRETTY_PRINT,
1019                                  !(indent & JS_DONT_PRETTY_PRINT),
1020 @@ -5009,36 +4983,34 @@ JS_DecompileFunctionBody(JSContext *cx, 
1021      assertSameCompartment(cx, fun);
1022      return js_DecompileToString(cx, "JS_DecompileFunctionBody", fun,
1023                                  indent & ~JS_DONT_PRETTY_PRINT,
1024                                  !(indent & JS_DONT_PRETTY_PRINT),
1025                                  false, false, js_DecompileFunctionBody);
1026  }
1027  
1028  JS_PUBLIC_API(JSBool)
1029 -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval)
1030 +JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval)
1031  {
1032      JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
1033 -    JSBool ok;
1034  
1035      CHECK_REQUEST(cx);
1036 -    assertSameCompartment(cx, obj, script);
1037 -    /* This should receive only scripts handed out via the JSAPI. */
1038 -    JS_ASSERT(script->u.object);
1039 -    ok = Execute(cx, obj, script, NULL, 0, Valueify(rval));
1040 +    assertSameCompartment(cx, obj, scriptObj);
1041 +
1042 +    JSBool ok = Execute(cx, obj, scriptObj->getScript(), NULL, 0, Valueify(rval));
1043      LAST_FRAME_CHECKS(cx, ok);
1044      return ok;
1045  }
1046  
1047  JS_PUBLIC_API(JSBool)
1048 -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
1049 +JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval,
1050                          JSVersion version)
1051  {
1052      AutoVersionAPI ava(cx, version);
1053 -    return JS_ExecuteScript(cx, obj, script, rval);
1054 +    return JS_ExecuteScript(cx, obj, scriptObj, rval);
1055  }
1056  
1057  bool
1058  EvaluateUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj,
1059                                      JSPrincipals *principals,
1060                                      const jschar *chars, uintN length,
1061                                      const char *filename, uintN lineno,
1062                                      jsval *rval, JSVersion compileVersion)
1063 @@ -6184,30 +6156,16 @@ JS_ClearContextThread(JSContext *cx)
1064       * with the GC that may delete t.
1065       */
1066      return reinterpret_cast<jsword>(t->id);
1067  #else
1068      return 0;
1069  #endif
1070  }
1071  
1072 -#ifdef MOZ_TRACE_JSCALLS
1073 -JS_PUBLIC_API(void)
1074 -JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb)
1075 -{
1076 -    cx->functionCallback = fcb;
1077 -}
1078 -
1079 -JS_PUBLIC_API(JSFunctionCallback)
1080 -JS_GetFunctionCallback(JSContext *cx)
1081 -{
1082 -    return cx->functionCallback;
1083 -}
1084 -#endif
1085 -
1086  #ifdef JS_GC_ZEAL
1087  JS_PUBLIC_API(void)
1088  JS_SetGCZeal(JSContext *cx, uint8 zeal)
1089  {
1090      cx->runtime->gcZeal = zeal;
1091  }
1092  #endif
1093  
1094 diff --git a/js/src/jsapi.h b/js/src/jsapi.h
1095 --- a/js/src/jsapi.h
1096 +++ b/js/src/jsapi.h
1097 @@ -983,19 +983,16 @@ JS_SetCompartmentCallback(JSRuntime *rt,
1098  extern JS_PUBLIC_API(JSWrapObjectCallback)
1099  JS_SetWrapObjectCallbacks(JSRuntime *rt,
1100                            JSWrapObjectCallback callback,
1101                            JSPreWrapCallback precallback);
1102  
1103  extern JS_PUBLIC_API(JSCrossCompartmentCall *)
1104  JS_EnterCrossCompartmentCall(JSContext *cx, JSObject *target);
1105  
1106 -extern JS_PUBLIC_API(JSCrossCompartmentCall *)
1107 -JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target);
1108 -
1109  extern JS_PUBLIC_API(void)
1110  JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call);
1111  
1112  extern JS_PUBLIC_API(void *)
1113  JS_SetCompartmentPrivate(JSContext *cx, JSCompartment *compartment, void *data);
1114  
1115  extern JS_PUBLIC_API(void *)
1116  JS_GetCompartmentPrivate(JSContext *cx, JSCompartment *compartment);
1117 @@ -1030,18 +1027,16 @@ class JS_PUBLIC_API(JSAutoEnterCompartme
1118  {
1119      JSCrossCompartmentCall *call;
1120  
1121    public:
1122      JSAutoEnterCompartment() : call(NULL) {}
1123  
1124      bool enter(JSContext *cx, JSObject *target);
1125  
1126 -    bool enter(JSContext *cx, JSScript *target);
1127 -
1128      void enterAndIgnoreErrors(JSContext *cx, JSObject *target);
1129  
1130      bool entered() const { return call != NULL; }
1131  
1132      ~JSAutoEnterCompartment() {
1133          if (call && call != reinterpret_cast<JSCrossCompartmentCall*>(1))
1134              JS_LeaveCrossCompartmentCall(call);
1135      }
1136 @@ -1468,16 +1463,23 @@ inline Anchor<jsval>::~Anchor() {
1137  #endif
1138  
1139  }  /* namespace JS */
1140  
1141  JS_BEGIN_EXTERN_C
1142  #endif
1143  
1144  /*
1145 + * C-compatible version of the Anchor class. It should be called after the last
1146 + * use of the variable it protects.
1147 + */
1148 +extern JS_NEVER_INLINE JS_PUBLIC_API(void)
1149 +JS_AnchorPtr(void *p);
1150 +
1151 +/*
1152   * This symbol may be used by embedders to detect the change from the old
1153   * JS_AddRoot(JSContext *, void *) APIs to the new ones above.
1154   */
1155  #define JS_TYPED_ROOTING_API
1156  
1157  /* Obsolete rooting APIs. */
1158  #define JS_ClearNewbornRoots(cx) ((void) 0)
1159  #define JS_EnterLocalRootScope(cx) (JS_TRUE)
1160 @@ -2653,106 +2655,70 @@ JS_CloneFunctionObject(JSContext *cx, JS
1161   * JS_TRUE.  The intent is to support interactive compilation - accumulate
1162   * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
1163   * the compiler.
1164   */
1165  extern JS_PUBLIC_API(JSBool)
1166  JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
1167                            const char *bytes, size_t length);
1168  
1169 -/*
1170 - * The JSScript objects returned by the following functions refer to string and
1171 - * other kinds of literals, including doubles and RegExp objects.  These
1172 - * literals are vulnerable to garbage collection; to root script objects and
1173 - * prevent literals from being collected, create a rootable object using
1174 - * JS_NewScriptObject, and root the resulting object using JS_Add[Named]Root.
1175 - */
1176 -extern JS_PUBLIC_API(JSScript *)
1177 +extern JS_PUBLIC_API(JSObject *)
1178  JS_CompileScript(JSContext *cx, JSObject *obj,
1179                   const char *bytes, size_t length,
1180                   const char *filename, uintN lineno);
1181  
1182 -extern JS_PUBLIC_API(JSScript *)
1183 +extern JS_PUBLIC_API(JSObject *)
1184  JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
1185                                JSPrincipals *principals,
1186                                const char *bytes, size_t length,
1187                                const char *filename, uintN lineno);
1188  
1189 -extern JS_PUBLIC_API(JSScript *)
1190 +extern JS_PUBLIC_API(JSObject *)
1191  JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
1192                                       JSPrincipals *principals,
1193                                       const char *bytes, size_t length,
1194                                       const char *filename, uintN lineno,
1195                                       JSVersion version);
1196  
1197 -extern JS_PUBLIC_API(JSScript *)
1198 +extern JS_PUBLIC_API(JSObject *)
1199  JS_CompileUCScript(JSContext *cx, JSObject *obj,
1200                     const jschar *chars, size_t length,
1201                     const char *filename, uintN lineno);
1202  
1203 -extern JS_PUBLIC_API(JSScript *)
1204 +extern JS_PUBLIC_API(JSObject *)
1205  JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
1206                                  JSPrincipals *principals,
1207                                  const jschar *chars, size_t length,
1208                                  const char *filename, uintN lineno);
1209  
1210 -extern JS_PUBLIC_API(JSScript *)
1211 +extern JS_PUBLIC_API(JSObject *)
1212  JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
1213                                         JSPrincipals *principals,
1214                                         const jschar *chars, size_t length,
1215                                         const char *filename, uintN lineno,
1216                                         JSVersion version);
1217  
1218 -extern JS_PUBLIC_API(JSScript *)
1219 +extern JS_PUBLIC_API(JSObject *)
1220  JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
1221  
1222 -extern JS_PUBLIC_API(JSScript *)
1223 +extern JS_PUBLIC_API(JSObject *)
1224  JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
1225                       FILE *fh);
1226  
1227 -extern JS_PUBLIC_API(JSScript *)
1228 +extern JS_PUBLIC_API(JSObject *)
1229  JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
1230                                    const char *filename, FILE *fh,
1231                                    JSPrincipals *principals);
1232  
1233 -extern JS_PUBLIC_API(JSScript *)
1234 +extern JS_PUBLIC_API(JSObject *)
1235  JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
1236                                           const char *filename, FILE *fh,
1237                                           JSPrincipals *principals,
1238                                           JSVersion version);
1239  
1240 -/*
1241 - * NB: you must use JS_NewScriptObject and root a pointer to its return value
1242 - * in order to keep a JSScript and its atoms safe from garbage collection after
1243 - * creating the script via JS_Compile* and before a JS_ExecuteScript* call.
1244 - * E.g., and without error checks:
1245 - *
1246 - *    JSScript *script = JS_CompileFile(cx, global, filename);
1247 - *    JSObject *scrobj = JS_NewScriptObject(cx, script);
1248 - *    JS_AddNamedObjectRoot(cx, &scrobj, "scrobj");
1249 - *    do {
1250 - *        jsval result;
1251 - *        JS_ExecuteScript(cx, global, script, &result);
1252 - *        JS_GC();
1253 - *    } while (!JSVAL_IS_BOOLEAN(result) || JSVAL_TO_BOOLEAN(result));
1254 - *    JS_RemoveObjectRoot(cx, &scrobj);
1255 - */
1256 -extern JS_PUBLIC_API(JSObject *)
1257 -JS_NewScriptObject(JSContext *cx, JSScript *script);
1258 -
1259 -/*
1260 - * Infallible getter for a script's object.  If JS_NewScriptObject has not been
1261 - * called on script yet, the return value will be null.
1262 - */
1263 -extern JS_PUBLIC_API(JSObject *)
1264 -JS_GetScriptObject(JSScript *script);
1265 -
1266 -extern JS_PUBLIC_API(void)
1267 -JS_DestroyScript(JSContext *cx, JSScript *script);
1268 -
1269  extern JS_PUBLIC_API(JSFunction *)
1270  JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
1271                     uintN nargs, const char **argnames,
1272                     const char *bytes, size_t length,
1273                     const char *filename, uintN lineno);
1274  
1275  extern JS_PUBLIC_API(JSFunction *)
1276  JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
1277 @@ -2778,18 +2744,17 @@ extern JS_PUBLIC_API(JSFunction *)
1278  JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
1279                                           JSPrincipals *principals, const char *name,
1280                                           uintN nargs, const char **argnames,
1281                                           const jschar *chars, size_t length,
1282                                           const char *filename, uintN lineno,
1283                                           JSVersion version);
1284  
1285  extern JS_PUBLIC_API(JSString *)
1286 -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
1287 -                   uintN indent);
1288 +JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent);
1289  
1290  /*
1291   * API extension: OR this into indent to avoid pretty-printing the decompiled
1292   * source resulting from JS_DecompileFunction{,Body}.
1293   */
1294  #define JS_DONT_PRETTY_PRINT    ((uintN)0x8000)
1295  
1296  extern JS_PUBLIC_API(JSString *)
1297 @@ -2829,20 +2794,20 @@ JS_DecompileFunctionBody(JSContext *cx, 
1298   * points with signatures matching the following six, and that doesn't seem
1299   * worth the code bloat cost.  Such new entry points would probably have less
1300   * obvious names, too, so would not tend to be used.  The JS_SetOption call,
1301   * OTOH, can be more easily hacked into existing code that does not depend on
1302   * the bug; such code can continue to use the familiar JS_EvaluateScript,
1303   * etc., entry points.
1304   */
1305  extern JS_PUBLIC_API(JSBool)
1306 -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
1307 +JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval);
1308  
1309  extern JS_PUBLIC_API(JSBool)
1310 -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
1311 +JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval,
1312                          JSVersion version);
1313  
1314  /*
1315   * Execute either the function-defining prolog of a script, or the script's
1316   * main body, but not both.
1317   */
1318  typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
1319  
1320 @@ -3775,38 +3740,16 @@ extern JS_PUBLIC_API(jsword)
1321  JS_GetContextThread(JSContext *cx);
1322  
1323  extern JS_PUBLIC_API(jsword)
1324  JS_SetContextThread(JSContext *cx);
1325  
1326  extern JS_PUBLIC_API(jsword)
1327  JS_ClearContextThread(JSContext *cx);
1328  
1329 -#ifdef MOZ_TRACE_JSCALLS
1330 -typedef void (*JSFunctionCallback)(const JSFunction *fun,
1331 -                                   const JSScript *scr,
1332 -                                   const JSContext *cx,
1333 -                                   int entering);
1334 -
1335 -/*
1336 - * The callback is expected to be quick and noninvasive. It should not
1337 - * trigger interrupts, turn on debugging, or produce uncaught JS
1338 - * exceptions. The state of the stack and registers in the context
1339 - * cannot be relied upon, since this callback may be invoked directly
1340 - * from either JIT. The 'entering' field means we are entering a
1341 - * function if it is positive, leaving a function if it is zero or
1342 - * negative.
1343 - */
1344 -extern JS_PUBLIC_API(void)
1345 -JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb);
1346 -
1347 -extern JS_PUBLIC_API(JSFunctionCallback)
1348 -JS_GetFunctionCallback(JSContext *cx);
1349 -#endif
1350 -
1351  /************************************************************************/
1352  
1353  /*
1354   * JS_IsConstructing must be called from within a native given the
1355   * native's original cx and vp arguments. If JS_IsConstructing is true,
1356   * JS_THIS must not be used; the constructor should construct and return a
1357   * new object. Otherwise, the native is called as an ordinary function and
1358   * JS_THIS may be used.
1359 diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp
1360 --- a/js/src/jsarray.cpp
1361 +++ b/js/src/jsarray.cpp
1362 @@ -86,17 +86,16 @@
1363  #include "jsarray.h"
1364  #include "jsatom.h"
1365  #include "jsbit.h"
1366  #include "jsbool.h"
1367  #include "jstracer.h"
1368  #include "jsbuiltins.h"
1369  #include "jscntxt.h"
1370  #include "jsversion.h"
1371 -#include "jsdbgapi.h" /* for js_TraceWatchPoints */
1372  #include "jsfun.h"
1373  #include "jsgc.h"
1374  #include "jsinterp.h"
1375  #include "jsiter.h"
1376  #include "jslock.h"
1377  #include "jsnum.h"
1378  #include "jsobj.h"
1379  #include "jsscope.h"
1380 diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp
1381 --- a/js/src/jsdbgapi.cpp
1382 +++ b/js/src/jsdbgapi.cpp
1383 @@ -155,17 +155,17 @@ JS_SetDebugModeForCompartment(JSContext 
1384  
1385      // All scripts compiled from this point on should be in the requested debugMode.
1386      comp->debugMode = !!debug;
1387  
1388      // Discard JIT code for any scripts that change debugMode. This function
1389      // assumes that 'comp' is in the same thread as 'cx'.
1390  
1391  #ifdef JS_METHODJIT
1392 -    JSAutoEnterCompartment ac;
1393 +    JS::AutoEnterScriptCompartment ac;
1394  
1395      for (JSScript *script = (JSScript *)comp->scripts.next;
1396           &script->links != &comp->scripts;
1397           script = (JSScript *)script->links.next)
1398      {
1399          if (!script->debugMode == !debug)
1400              continue;
1401  
1402 @@ -2666,8 +2666,25 @@ js_ShutdownEthogram(JSContext *cx, uintN
1403      if (traceVisScriptTable)
1404          JS_HashTableDestroy(traceVisScriptTable);
1405  
1406      JS_SET_RVAL(cx, vp, JSVAL_VOID);
1407      return true;
1408  }
1409  
1410  #endif /* MOZ_TRACEVIS */
1411 +
1412 +#ifdef MOZ_TRACE_JSCALLS
1413 +
1414 +JS_PUBLIC_API(void)
1415 +JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb)
1416 +{
1417 +    cx->functionCallback = fcb;
1418 +}
1419 +
1420 +JS_PUBLIC_API(JSFunctionCallback)
1421 +JS_GetFunctionCallback(JSContext *cx)
1422 +{
1423 +    return cx->functionCallback;
1424 +}
1425 +
1426 +#endif /* MOZ_TRACE_JSCALLS */
1427 +
1428 diff --git a/js/src/jsdbgapi.h b/js/src/jsdbgapi.h
1429 --- a/js/src/jsdbgapi.h
1430 +++ b/js/src/jsdbgapi.h
1431 @@ -1,9 +1,9 @@
1432 -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1433 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1434   * vim: set ts=8 sw=4 et tw=99:
1435   *
1436   * ***** BEGIN LICENSE BLOCK *****
1437   * Version: MPL 1.1/GPL 2.0/LGPL 2.1
1438   *
1439   * The contents of this file are subject to the Mozilla Public License Version
1440   * 1.1 (the "License"); you may not use this file except in compliance with
1441   * the License. You may obtain a copy of the License at
1442 @@ -44,16 +44,52 @@
1443   * JS debugger API.
1444   */
1445  #include "jsapi.h"
1446  #include "jsopcode.h"
1447  #include "jsprvtd.h"
1448  
1449  JS_BEGIN_EXTERN_C
1450  
1451 +extern JS_PUBLIC_API(JSCrossCompartmentCall *)
1452 +JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target);
1453 +
1454 +#ifdef __cplusplus
1455 +JS_END_EXTERN_C
1456 +
1457 +namespace JS {
1458 +
1459 +class JS_PUBLIC_API(AutoEnterScriptCompartment)
1460 +{
1461 +    JSCrossCompartmentCall *call;
1462 +
1463 +  public:
1464 +    AutoEnterScriptCompartment() : call(NULL) {}
1465 +
1466 +    bool enter(JSContext *cx, JSScript *target);
1467 +
1468 +    bool entered() const { return call != NULL; }
1469 +
1470 +    ~AutoEnterScriptCompartment() {
1471 +        if (call && call != reinterpret_cast<JSCrossCompartmentCall*>(1))
1472 +            JS_LeaveCrossCompartmentCall(call);
1473 +    }
1474 +};
1475 +
1476 +} /* namespace JS */
1477 +
1478 +JS_BEGIN_EXTERN_C
1479 +#endif
1480 +
1481 +extern JS_PUBLIC_API(JSScript *)
1482 +JS_GetScriptFromObject(JSObject *scriptObject);
1483 +
1484 +extern JS_PUBLIC_API(JSString *)
1485 +JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent);
1486 +
1487  /*
1488   * Currently, we only support runtime-wide debugging. In the future, we should
1489   * be able to support compartment-wide debugging.
1490   */
1491  extern JS_PUBLIC_API(void)
1492  JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug);
1493  
1494  /*
1495 @@ -558,11 +594,33 @@ js_ResumeVtune(JSContext *cx, uintN argc
1496  
1497  #ifdef MOZ_TRACEVIS
1498  extern JS_FRIEND_API(JSBool)
1499  js_InitEthogram(JSContext *cx, uintN argc, jsval *vp);
1500  extern JS_FRIEND_API(JSBool)
1501  js_ShutdownEthogram(JSContext *cx, uintN argc, jsval *vp);
1502  #endif /* MOZ_TRACEVIS */
1503  
1504 +#ifdef MOZ_TRACE_JSCALLS
1505 +typedef void (*JSFunctionCallback)(const JSFunction *fun,
1506 +                                   const JSScript *scr,
1507 +                                   const JSContext *cx,
1508 +                                   int entering);
1509 +
1510 +/*
1511 + * The callback is expected to be quick and noninvasive. It should not
1512 + * trigger interrupts, turn on debugging, or produce uncaught JS
1513 + * exceptions. The state of the stack and registers in the context
1514 + * cannot be relied upon, since this callback may be invoked directly
1515 + * from either JIT. The 'entering' field means we are entering a
1516 + * function if it is positive, leaving a function if it is zero or
1517 + * negative.
1518 + */
1519 +extern JS_PUBLIC_API(void)
1520 +JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb);
1521 +
1522 +extern JS_PUBLIC_API(JSFunctionCallback)
1523 +JS_GetFunctionCallback(JSContext *cx);
1524 +#endif /* MOZ_TRACE_JSCALLS */
1525 +
1526  JS_END_EXTERN_C
1527  
1528  #endif /* jsdbgapi_h___ */
1529 diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp
1530 --- a/js/src/jsexn.cpp
1531 +++ b/js/src/jsexn.cpp
1532 @@ -46,17 +46,16 @@
1533  #include "jstypes.h"
1534  #include "jsstdint.h"
1535  #include "jsbit.h"
1536  #include "jsutil.h"
1537  #include "jsprf.h"
1538  #include "jsapi.h"
1539  #include "jscntxt.h"
1540  #include "jsversion.h"
1541 -#include "jsdbgapi.h"
1542  #include "jsexn.h"
1543  #include "jsfun.h"
1544  #include "jsinterp.h"
1545  #include "jsnum.h"
1546  #include "jsobj.h"
1547  #include "jsopcode.h"
1548  #include "jsscope.h"
1549  #include "jsscript.h"
1550 diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp
1551 --- a/js/src/jsfun.cpp
1552 +++ b/js/src/jsfun.cpp
1553 @@ -48,17 +48,16 @@
1554  #include "jsutil.h"
1555  #include "jsapi.h"
1556  #include "jsarray.h"
1557  #include "jsatom.h"
1558  #include "jsbool.h"
1559  #include "jsbuiltins.h"
1560  #include "jscntxt.h"
1561  #include "jsversion.h"
1562 -#include "jsdbgapi.h"
1563  #include "jsemit.h"
1564  #include "jsfun.h"
1565  #include "jsgc.h"
1566  #include "jsinterp.h"
1567  #include "jslock.h"
1568  #include "jsnum.h"
1569  #include "jsobj.h"
1570  #include "jsopcode.h"
1571 diff --git a/js/src/jsobj.h b/js/src/jsobj.h
1572 --- a/js/src/jsobj.h
1573 +++ b/js/src/jsobj.h
1574 @@ -1049,16 +1049,22 @@ struct JSObject : js::gc::Cell {
1575      /*
1576       * Iterator-specific getters and setters.
1577       */
1578  
1579      inline js::NativeIterator *getNativeIterator() const;
1580      inline void setNativeIterator(js::NativeIterator *);
1581  
1582      /*
1583 +     * Script-related getters.
1584 +     */
1585 +
1586 +    inline JSScript *getScript() const;
1587 +
1588 +    /*
1589       * XML-related getters and setters.
1590       */
1591  
1592      /*
1593       * Slots for XML-related classes are as follows:
1594       * - js_NamespaceClass.base reserves the *_NAME_* and *_NAMESPACE_* slots.
1595       * - js_QNameClass.base, js_AttributeNameClass, js_AnyNameClass reserve
1596       *   the *_NAME_* and *_QNAME_* slots.
1597 @@ -1291,16 +1297,17 @@ struct JSObject : js::gc::Cell {
1598      inline bool isFunction() const;
1599      inline bool isObject() const;
1600      inline bool isWith() const;
1601      inline bool isBlock() const;
1602      inline bool isStaticBlock() const;
1603      inline bool isClonedBlock() const;
1604      inline bool isCall() const;
1605      inline bool isRegExp() const;
1606 +    inline bool isScript() const;
1607      inline bool isXML() const;
1608      inline bool isXMLId() const;
1609      inline bool isNamespace() const;
1610      inline bool isQName() const;
1611  
1612      inline bool isProxy() const;
1613      inline bool isObjectProxy() const;
1614      inline bool isFunctionProxy() const;
1615 diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp
1616 --- a/js/src/jsopcode.cpp
1617 +++ b/js/src/jsopcode.cpp
1618 @@ -53,17 +53,16 @@
1619  #include "jsarena.h"
1620  #include "jsutil.h"
1621  #include "jsprf.h"
1622  #include "jsapi.h"
1623  #include "jsarray.h"
1624  #include "jsatom.h"
1625  #include "jscntxt.h"
1626  #include "jsversion.h"
1627 -#include "jsdbgapi.h"
1628  #include "jsemit.h"
1629  #include "jsfun.h"
1630  #include "jsiter.h"
1631  #include "jsnum.h"
1632  #include "jsobj.h"
1633  #include "jsopcode.h"
1634  #include "jsregexp.h"
1635  #include "jsscan.h"
1636 diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h
1637 --- a/js/src/jsprvtd.h
1638 +++ b/js/src/jsprvtd.h
1639 @@ -80,16 +80,17 @@ typedef struct JSArgumentFormatMap  JSAr
1640  typedef struct JSCodeGenerator      JSCodeGenerator;
1641  typedef struct JSGCThing            JSGCThing;
1642  typedef struct JSGenerator          JSGenerator;
1643  typedef struct JSNativeEnumerator   JSNativeEnumerator;
1644  typedef struct JSFunctionBox        JSFunctionBox;
1645  typedef struct JSObjectBox          JSObjectBox;
1646  typedef struct JSParseNode          JSParseNode;
1647  typedef struct JSProperty           JSProperty;
1648 +typedef struct JSScript             JSScript;
1649  typedef struct JSSharpObjectMap     JSSharpObjectMap;
1650  typedef struct JSThread             JSThread;
1651  typedef struct JSThreadData         JSThreadData;
1652  typedef struct JSTreeContext        JSTreeContext;
1653  typedef struct JSTryNote            JSTryNote;
1654  
1655  /* Friend "Advanced API" typedefs. */
1656  typedef struct JSLinearString       JSLinearString;
1657 diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h
1658 --- a/js/src/jspubtd.h
1659 +++ b/js/src/jspubtd.h
1660 @@ -151,17 +151,16 @@ typedef struct JSErrorReport     JSError
1661  typedef struct JSFunction        JSFunction;
1662  typedef struct JSFunctionSpec    JSFunctionSpec;
1663  typedef struct JSTracer          JSTracer;
1664  typedef struct JSIdArray         JSIdArray;
1665  typedef struct JSPropertyDescriptor JSPropertyDescriptor;
1666  typedef struct JSPropertySpec    JSPropertySpec;
1667  typedef struct JSObjectMap       JSObjectMap;
1668  typedef struct JSRuntime         JSRuntime;
1669 -typedef struct JSScript          JSScript;
1670  typedef struct JSStackFrame      JSStackFrame;
1671  typedef struct JSXDRState        JSXDRState;
1672  typedef struct JSExceptionState  JSExceptionState;
1673  typedef struct JSLocaleCallbacks JSLocaleCallbacks;
1674  typedef struct JSSecurityCallbacks JSSecurityCallbacks;
1675  typedef struct JSONParser        JSONParser;
1676  typedef struct JSCompartment     JSCompartment;
1677  typedef struct JSCrossCompartmentCall JSCrossCompartmentCall;
1678 @@ -462,22 +461,16 @@ typedef JSBool
1679   * stored in data.
1680   */
1681  typedef void
1682  (* JSTraceDataOp)(JSTracer *trc, void *data);
1683  
1684  typedef JSBool
1685  (* JSOperationCallback)(JSContext *cx);
1686  
1687 -/*
1688 - * Deprecated form of JSOperationCallback.
1689 - */
1690 -typedef JSBool
1691 -(* JSBranchCallback)(JSContext *cx, JSScript *script);
1692 -
1693  typedef void
1694  (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
1695  
1696  /*
1697   * Possible exception types. These types are part of a JSErrorFormatString
1698   * structure. They define which error to throw in case of a runtime error.
1699   * JSEXN_NONE marks an unthrowable error.
1700   */
1701 diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp
1702 --- a/js/src/jsscript.cpp
1703 +++ b/js/src/jsscript.cpp
1704 @@ -289,17 +289,17 @@ Bindings::makeImmutable()
1705  
1706  void
1707  Bindings::trace(JSTracer *trc)
1708  {
1709      for (const Shape *shape = lastBinding; shape; shape = shape->previous())
1710          shape->trace(trc);
1711  }
1712  
1713 -} // namespace js
1714 +} /* namespace js */
1715  
1716  #if JS_HAS_XDR
1717  
1718  enum ScriptBits {
1719      NoScriptRval,
1720      SavedCallerFun,
1721      HasSharps,
1722      StrictModeCode,
1723 @@ -1700,40 +1700,40 @@ js_TraceScript(JSTracer *trc, JSScript *
1724      }
1725  
1726      if (IS_GC_MARKING_TRACER(trc) && script->filename)
1727          js_MarkScriptFilename(script->filename);
1728  
1729      script->bindings.trace(trc);
1730  }
1731  
1732 -JSBool
1733 +JSObject *
1734  js_NewScriptObject(JSContext *cx, JSScript *script)
1735  {
1736      AutoScriptRooter root(cx, script);
1737  
1738      JS_ASSERT(!script->u.object);
1739  
1740      JSObject *obj = NewNonFunction<WithProto::Class>(cx, &js_ScriptClass, NULL, NULL);
1741      if (!obj)
1742 -        return JS_FALSE;
1743 +        return NULL;
1744      obj->setPrivate(script);
1745      script->u.object = obj;
1746  
1747      /*
1748       * Clear the object's proto, to avoid entraining stuff. Once we no longer use the parent
1749       * for security checks, then we can clear the parent, too.
1750       */
1751      obj->clearProto();
1752  
1753  #ifdef CHECK_SCRIPT_OWNER
1754      script->owner = NULL;
1755  #endif
1756  
1757 -    return JS_TRUE;
1758 +    return obj;
1759  }
1760  
1761  typedef struct GSNCacheEntry {
1762      JSDHashEntryHdr     hdr;
1763      jsbytecode          *pc;
1764      jssrcnote           *sn;
1765  } GSNCacheEntry;
1766  
1767 @@ -1968,17 +1968,17 @@ js_CloneScript(JSContext *cx, JSScript *
1768      // serialize script
1769      JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
1770      if (!w)
1771          return NULL;
1772  
1773      // we don't want gecko to transcribe our principals for us
1774      DisablePrincipalsTranscoding disable(cx);
1775  
1776 -    if (!JS_XDRScript(w, &script)) {
1777 +    if (!js_XDRScript(w, &script, NULL)) {
1778          JS_XDRDestroy(w);
1779          return NULL;
1780      }
1781  
1782      uint32 nbytes;
1783      void *p = JS_XDRMemGetData(w, &nbytes);
1784      if (!p) {
1785          JS_XDRDestroy(w);
1786 @@ -1992,17 +1992,16 @@ js_CloneScript(JSContext *cx, JSScript *
1787          return NULL;
1788      }
1789  
1790      // Hand p off from w to r.  Don't want them to share the data
1791      // mem, lest they both try to free it in JS_XDRDestroy
1792      JS_XDRMemSetData(r, p, nbytes);
1793      JS_XDRMemSetData(w, NULL, 0);
1794  
1795 -    // We can't use the public API because it makes a script object.
1796      if (!js_XDRScript(r, &script, NULL))
1797          return NULL;
1798  
1799      JS_XDRDestroy(r);
1800      JS_XDRDestroy(w);
1801  
1802      // set the proper principals for the script
1803      script->principals = script->compartment->principals;
1804 diff --git a/js/src/jsscript.h b/js/src/jsscript.h
1805 --- a/js/src/jsscript.h
1806 +++ b/js/src/jsscript.h
1807 @@ -674,17 +674,17 @@ js_DestroyScriptFromGC(JSContext *cx, JS
1808   * is already dead.
1809   */
1810  extern void
1811  js_DestroyCachedScript(JSContext *cx, JSScript *script);
1812  
1813  extern void
1814  js_TraceScript(JSTracer *trc, JSScript *script);
1815  
1816 -extern JSBool
1817 +extern JSObject *
1818  js_NewScriptObject(JSContext *cx, JSScript *script);
1819  
1820  /*
1821   * To perturb as little code as possible, we introduce a js_GetSrcNote lookup
1822   * cache without adding an explicit cx parameter.  Thus js_GetSrcNote becomes
1823   * a macro that uses cx from its calls' lexical environments.
1824   */
1825  #define js_GetSrcNote(script,pc) js_GetSrcNoteCached(cx, script, pc)
1826 @@ -729,9 +729,22 @@ js_CloneScript(JSContext *cx, JSScript *
1827   *
1828   * NB: after a successful JSXDR_DECODE, js_XDRScript callers must do any
1829   * required subsequent set-up of owning function or script object and then call
1830   * js_CallNewScriptHook.
1831   */
1832  extern JSBool
1833  js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic);
1834  
1835 +inline bool
1836 +JSObject::isScript() const
1837 +{
1838 +    return getClass() == &js_ScriptClass;
1839 +}
1840 +
1841 +inline JSScript *
1842 +JSObject::getScript() const
1843 +{
1844 +    JS_ASSERT(isScript());
1845 +    return static_cast<JSScript *>(getPrivate());
1846 +}
1847 +
1848  #endif /* jsscript_h___ */
1849 diff --git a/js/src/jsxdrapi.cpp b/js/src/jsxdrapi.cpp
1850 --- a/js/src/jsxdrapi.cpp
1851 +++ b/js/src/jsxdrapi.cpp
1852 @@ -661,31 +661,39 @@ js_XDRAtom(JSXDRState *xdr, JSAtom **ato
1853  
1854      if (!atom)
1855          return JS_FALSE;
1856      *atomp = atom;
1857      return JS_TRUE;
1858  }
1859  
1860  JS_PUBLIC_API(JSBool)
1861 -JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
1862 +JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp)
1863  {
1864 -    if (!js_XDRScript(xdr, scriptp, NULL))
1865 -        return JS_FALSE;
1866 +    JSScript *script;
1867 +    if (xdr->mode == JSXDR_DECODE) {
1868 +        script = NULL;
1869 +        *scriptObjp = NULL;
1870 +    } else {
1871 +        script = (*scriptObjp)->getScript();
1872 +    }
1873 +    
1874 +    if (!js_XDRScript(xdr, &script, NULL))
1875 +        return false;
1876  
1877      if (xdr->mode == JSXDR_DECODE) {
1878 -        js_CallNewScriptHook(xdr->cx, *scriptp, NULL);
1879 -        if (!js_NewScriptObject(xdr->cx, *scriptp)) {
1880 -            js_DestroyScript(xdr->cx, *scriptp);
1881 -            *scriptp = NULL;
1882 -            return JS_FALSE;
1883 +        js_CallNewScriptHook(xdr->cx, script, NULL);
1884 +        *scriptObjp = js_NewScriptObject(xdr->cx, script);
1885 +        if (!*scriptObjp) {
1886 +            js_DestroyScript(xdr->cx, script);
1887 +            return false;
1888          }
1889      }
1890  
1891 -    return JS_TRUE;
1892 +    return true;
1893  }
1894  
1895  #define CLASS_REGISTRY_MIN      8
1896  #define CLASS_INDEX_TO_ID(i)    ((i)+1)
1897  #define CLASS_ID_TO_INDEX(id)   ((id)-1)
1898  
1899  typedef struct JSRegHashEntry {
1900      JSDHashEntryHdr hdr;
1901 diff --git a/js/src/jsxdrapi.h b/js/src/jsxdrapi.h
1902 --- a/js/src/jsxdrapi.h
1903 +++ b/js/src/jsxdrapi.h
1904 @@ -165,17 +165,17 @@ JS_XDRStringOrNull(JSXDRState *xdr, JSSt
1905  
1906  extern JS_PUBLIC_API(JSBool)
1907  JS_XDRDouble(JSXDRState *xdr, jsdouble *dp);
1908  
1909  extern JS_PUBLIC_API(JSBool)
1910  JS_XDRValue(JSXDRState *xdr, jsval *vp);
1911  
1912  extern JS_PUBLIC_API(JSBool)
1913 -JS_XDRScript(JSXDRState *xdr, JSScript **scriptp);
1914 +JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp);
1915  
1916  extern JS_PUBLIC_API(JSBool)
1917  JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *lp);
1918  
1919  extern JS_PUBLIC_API(uint32)
1920  JS_XDRFindClassIdByName(JSXDRState *xdr, const char *name);
1921  
1922  extern JS_PUBLIC_API(JSClass *)
1923 diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
1924 --- a/js/src/shell/js.cpp
1925 +++ b/js/src/shell/js.cpp
1926 @@ -392,17 +392,17 @@ SetContextOptions(JSContext *cx)
1927  #ifdef WINCE
1928  int errno;
1929  #endif
1930  
1931  static void
1932  Process(JSContext *cx, JSObject *obj, char *filename, JSBool forceTTY)
1933  {
1934      JSBool ok, hitEOF;
1935 -    JSScript *script;
1936 +    JSObject *scriptObj;
1937      jsval result;
1938      JSString *str;
1939      char *buffer;
1940      size_t size;
1941      int lineno;
1942      int startline;
1943      FILE *file;
1944      uint32 oldopts;
1945 @@ -441,20 +441,20 @@ Process(JSContext *cx, JSObject *obj, ch
1946                      break;
1947              }
1948          }
1949          ungetc(ch, file);
1950  
1951          int64 t1 = PRMJ_Now();
1952          oldopts = JS_GetOptions(cx);
1953          JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
1954 -        script = JS_CompileFileHandle(cx, obj, filename, file);
1955 +        scriptObj = JS_CompileFileHandle(cx, obj, filename, file);
1956          JS_SetOptions(cx, oldopts);
1957 -        if (script && !compileOnly) {
1958 -            (void)JS_ExecuteScript(cx, obj, script, NULL);
1959 +        if (scriptObj && !compileOnly) {
1960 +            (void) JS_ExecuteScript(cx, obj, scriptObj, NULL);
1961              int64 t2 = PRMJ_Now() - t1;
1962              if (printTiming)
1963                  printf("runtime = %.3f ms\n", double(t2) / PRMJ_USEC_PER_MSEC);
1964          }
1965  
1966          goto cleanup;
1967      }
1968  
1969 @@ -530,23 +530,23 @@ Process(JSContext *cx, JSObject *obj, ch
1970  
1971          /* Clear any pending exception from previous failed compiles. */
1972          JS_ClearPendingException(cx);
1973  
1974          /* Even though we're interactive, we have a compile-n-go opportunity. */
1975          oldopts = JS_GetOptions(cx);
1976          if (!compileOnly)
1977              JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO);
1978 -        script = JS_CompileScript(cx, obj, buffer, len, "typein",
1979 -                                  startline);
1980 +        scriptObj = JS_CompileScript(cx, obj, buffer, len, "typein",
1981 +                                     startline);
1982          if (!compileOnly)
1983              JS_SetOptions(cx, oldopts);
1984  
1985 -        if (script && !compileOnly) {
1986 -            ok = JS_ExecuteScript(cx, obj, script, &result);
1987 +        if (scriptObj && !compileOnly) {
1988 +            ok = JS_ExecuteScript(cx, obj, scriptObj, &result);
1989              if (ok && !JSVAL_IS_VOID(result)) {
1990                  str = JS_ValueToSource(cx, result);
1991                  ok = !!str;
1992                  if (ok) {
1993                      JSAutoByteString bytes(cx, str);
1994                      ok = !!bytes;
1995                      if (ok)
1996                          fprintf(gOutFile, "%s\n", bytes.ptr());
1997 @@ -1013,46 +1013,42 @@ Options(JSContext *cx, uintN argc, jsval
1998          return JS_FALSE;
1999      *vp = STRING_TO_JSVAL(str);
2000      return JS_TRUE;
2001  }
2002  
2003  static JSBool
2004  Load(JSContext *cx, uintN argc, jsval *vp)
2005  {
2006 -    uintN i;
2007 -    JSString *str;
2008 -    JSScript *script;
2009 -    uint32 oldopts;
2010 -
2011      JSObject *thisobj = JS_THIS_OBJECT(cx, vp);
2012      if (!thisobj)
2013          return JS_FALSE;
2014  
2015      jsval *argv = JS_ARGV(cx, vp);
2016 -    for (i = 0; i < argc; i++) {
2017 -        str = JS_ValueToString(cx, argv[i]);
2018 +    for (uintN i = 0; i < argc; i++) {
2019 +        JSString *str = JS_ValueToString(cx, argv[i]);
2020          if (!str)
2021 -            return JS_FALSE;
2022 +            return false;
2023          argv[i] = STRING_TO_JSVAL(str);
2024          JSAutoByteString filename(cx, str);
2025          if (!filename)
2026              return JS_FALSE;
2027          errno = 0;
2028 -        oldopts = JS_GetOptions(cx);
2029 +        uint32 oldopts = JS_GetOptions(cx);
2030          JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
2031 -        script = JS_CompileFile(cx, thisobj, filename.ptr());
2032 -        if (!script)
2033 -            return JS_FALSE;
2034 +        JSObject *scriptObj = JS_CompileFile(cx, thisobj, filename.ptr());
2035          JS_SetOptions(cx, oldopts);
2036 -        if (!compileOnly && !JS_ExecuteScript(cx, thisobj, script, NULL))
2037 -            return JS_FALSE;
2038 -    }
2039 -
2040 -    return JS_TRUE;
2041 +        if (!scriptObj)
2042 +            return false;
2043 +
2044 +        if (!compileOnly && !JS_ExecuteScript(cx, thisobj, scriptObj, NULL))
2045 +            return false;
2046 +    }
2047 +
2048 +    return true;
2049  }
2050  
2051  static JSBool
2052  Evaluate(JSContext *cx, uintN argc, jsval *vp)
2053  {
2054      if (argc != 1 || !JSVAL_IS_STRING(JS_ARGV(cx, vp)[0])) {
2055          JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL,
2056                               (argc != 1) ? JSSMSG_NOT_ENOUGH_ARGS : JSSMSG_INVALID_ARGS,
2057 @@ -1155,27 +1151,22 @@ Run(JSContext *cx, uintN argc, jsval *vp
2058      if (!ucbuf)
2059          return false;
2060  
2061      JS::Anchor<JSString *> a_str(str);
2062      uint32 oldopts = JS_GetOptions(cx);
2063      JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
2064  
2065      int64 startClock = PRMJ_Now();
2066 -    JSScript *script = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, filename.ptr(), 1);
2067 +    JSObject *scriptObj = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, filename.ptr(), 1);
2068      JS_SetOptions(cx, oldopts);
2069 -    if (!script)
2070 +    if (!scriptObj || !JS_ExecuteScript(cx, thisobj, scriptObj, NULL))
2071          return false;
2072  
2073 -    JSBool ok = JS_ExecuteScript(cx, thisobj, script, NULL);
2074      int64 endClock = PRMJ_Now();
2075 -    JS_DestroyScript(cx, script);
2076 -    if (!ok)
2077 -        return false;
2078 -
2079      JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL((endClock - startClock) / double(PRMJ_USEC_PER_MSEC)));
2080      return true;
2081  }
2082  
2083  /*
2084   * function readline()
2085   * Provides a hook for scripts to read a line from stdin.
2086   */
2087 @@ -2252,40 +2243,35 @@ DisassFile(JSContext *cx, uintN argc, js
2088          return JS_TRUE;
2089      }
2090  
2091      /* Support extra options at the start, just like Dissassemble. */
2092      uintN _argc = argc;
2093      argv += argc-1;
2094      argc = 1;
2095  
2096 -
2097      JSObject *thisobj = JS_THIS_OBJECT(cx, vp);
2098      if (!thisobj)
2099          return JS_FALSE;
2100  
2101      JSString *str = JS_ValueToString(cx, argv[0]);
2102      if (!str)
2103          return JS_FALSE;
2104      JSAutoByteString filename(cx, str);
2105      if (!filename)
2106          return JS_FALSE;
2107  
2108      uint32 oldopts = JS_GetOptions(cx);
2109      JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
2110 -    JSScript *script = JS_CompileFile(cx, thisobj, filename.ptr());
2111 +    JSObject *scriptObj = JS_CompileFile(cx, thisobj, filename.ptr());
2112      JS_SetOptions(cx, oldopts);
2113 -    if (!script)
2114 -        return JS_FALSE;
2115 -
2116 -    JSObject *obj = JS_NewScriptObject(cx, script);
2117 -    if (!obj)
2118 -        return JS_FALSE;
2119 -
2120 -    argv[0] = OBJECT_TO_JSVAL(obj); /* I like to root it, root it. */
2121 +    if (!scriptObj)
2122 +        return false;
2123 +
2124 +    argv[0] = OBJECT_TO_JSVAL(scriptObj);
2125      JSBool ok = Disassemble(cx, _argc, vp); /* gross, but works! */
2126      JS_SET_RVAL(cx, vp, JSVAL_VOID);
2127      return ok;
2128  }
2129  
2130  static JSBool
2131  DisassWithSrc(JSContext *cx, uintN argc, jsval *vp)
2132  {
2133 @@ -4313,20 +4299,20 @@ Compile(JSContext *cx, uintN argc, jsval
2134      jsval arg0 = JS_ARGV(cx, vp)[0];
2135      if (!JSVAL_IS_STRING(arg0)) {
2136          const char *typeName = JS_GetTypeName(cx, JS_TypeOfValue(cx, arg0));
2137          JS_ReportError(cx, "expected string to compile, got %s", typeName);
2138          return JS_FALSE;
2139      }
2140  
2141      JSString *scriptContents = JSVAL_TO_STRING(arg0);
2142 -    JSScript *result = JS_CompileUCScript(cx, NULL, JS_GetStringCharsZ(cx, scriptContents),
2143 -                                          JS_GetStringLength(scriptContents), "<string>", 0);
2144 -    if (!result)
2145 -        return JS_FALSE;
2146 +    if (!JS_CompileUCScript(cx, NULL, JS_GetStringCharsZ(cx, scriptContents),
2147 +                            JS_GetStringLength(scriptContents), "<string>", 0)) {
2148 +        return false;
2149 +    }
2150  
2151      JS_SET_RVAL(cx, vp, JSVAL_VOID);
2152      return JS_TRUE;
2153  }
2154  
2155  static JSBool
2156  Parse(JSContext *cx, uintN argc, jsval *vp)
2157  {
2158 diff --git a/js/src/shell/jsworkers.cpp b/js/src/shell/jsworkers.cpp
2159 --- a/js/src/shell/jsworkers.cpp
2160 +++ b/js/src/shell/jsworkers.cpp
2161 @@ -890,23 +890,22 @@ class InitEvent : public Event
2162          jsval s;
2163          if (!deserializeData(cx, &s))
2164              return fail;
2165          JS_ASSERT(JSVAL_IS_STRING(s));
2166          JSAutoByteString filename(cx, JSVAL_TO_STRING(s));
2167          if (!filename)
2168              return fail;
2169  
2170 -        JSScript *script = JS_CompileFile(cx, child->getGlobal(), filename.ptr());
2171 -        if (!script)
2172 +        JSObject *scriptObj = JS_CompileFile(cx, child->getGlobal(), filename.ptr());
2173 +        if (!scriptObj)
2174              return fail;
2175  
2176          AutoValueRooter rval(cx);
2177 -        JSBool ok = JS_ExecuteScript(cx, child->getGlobal(), script, Jsvalify(rval.addr()));
2178 -        JS_DestroyScript(cx, script);
2179 +        JSBool ok = JS_ExecuteScript(cx, child->getGlobal(), scriptObj, Jsvalify(rval.addr()));
2180          return Result(ok);
2181      }
2182  };
2183  
2184  class DownMessageEvent : public Event
2185  {
2186    public:
2187      static DownMessageEvent *create(JSContext *cx, Worker *child, jsval data) {
2188 diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
2189 --- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
2190 +++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
2191 @@ -341,35 +341,35 @@ ReportOnCaller(JSCLContextHelper &helper
2192      }
2193  
2194      return OutputError(cx, format, ap);
2195  }
2196  
2197  #ifdef MOZ_ENABLE_LIBXUL
2198  static nsresult
2199  ReadScriptFromStream(JSContext *cx, nsIObjectInputStream *stream,
2200 -                     JSScript **script)
2201 +                     JSObject **scriptObj)
2202  {
2203 -    *script = nsnull;
2204 +    *scriptObj = nsnull;
2205  
2206      PRUint32 size;
2207      nsresult rv = stream->Read32(&size);
2208      NS_ENSURE_SUCCESS(rv, rv);
2209  
2210      char *data;
2211      rv = stream->ReadBytes(size, &data);
2212      NS_ENSURE_SUCCESS(rv, rv);
2213  
2214      JSXDRState *xdr = JS_XDRNewMem(cx, JSXDR_DECODE);
2215      NS_ENSURE_TRUE(xdr, NS_ERROR_OUT_OF_MEMORY);
2216  
2217      xdr->userdata = stream;
2218      JS_XDRMemSetData(xdr, data, size);
2219  
2220 -    if (!JS_XDRScript(xdr, script)) {
2221 +    if (!JS_XDRScriptObject(xdr, scriptObj)) {
2222          rv = NS_ERROR_FAILURE;
2223      }
2224  
2225      // Update data in case ::JS_XDRScript called back into C++ code to
2226      // read an XPCOM object.
2227      //
2228      // In that case, the serialization process must have flushed a run
2229      // of counted bytes containing JS data at the point where the XPCOM
2230 @@ -400,26 +400,26 @@ ReadScriptFromStream(JSContext *cx, nsIO
2231      if (data) {
2232          nsMemory::Free(data);
2233      }
2234  
2235      return rv;
2236  }
2237  
2238  static nsresult
2239 -WriteScriptToStream(JSContext *cx, JSScript *script,
2240 +WriteScriptToStream(JSContext *cx, JSObject *scriptObj,
2241                      nsIObjectOutputStream *stream)
2242  {
2243      JSXDRState *xdr = JS_XDRNewMem(cx, JSXDR_ENCODE);
2244      NS_ENSURE_TRUE(xdr, NS_ERROR_OUT_OF_MEMORY);
2245  
2246      xdr->userdata = stream;
2247      nsresult rv = NS_OK;
2248  
2249 -    if (JS_XDRScript(xdr, &script)) {
2250 +    if (JS_XDRScriptObject(xdr, &scriptObj)) {
2251          // Get the encoded JSXDRState data and write it.  The JSXDRState owns
2252          // this buffer memory and will free it beneath ::JS_XDRDestroy.
2253          //
2254          // If an XPCOM object needs to be written in the midst of the JS XDR
2255          // encoding process, the C++ code called back from the JS engine (e.g.,
2256          // nsEncodeJSPrincipals in caps/src/nsJSPrincipals.cpp) will flush data
2257          // from the JSXDRState to aStream, then write the object, then return
2258          // to JS XDR code with xdr reset so new JS data is encoded at the front
2259 @@ -822,27 +822,16 @@ class JSPrincipalsHolder
2260      JSPrincipalsHolder(JSContext *cx, JSPrincipals *principals)
2261          : mCx(cx), mPrincipals(principals) {}
2262      ~JSPrincipalsHolder() { JSPRINCIPALS_DROP(mCx, mPrincipals); }
2263   private:
2264      JSContext *mCx;
2265      JSPrincipals *mPrincipals;
2266  };
2267  
2268 -class JSScriptHolder
2269 -{
2270 - public:
2271 -    JSScriptHolder(JSContext *cx, JSScript *script)
2272 -        : mCx(cx), mScript(script) {}
2273 -    ~JSScriptHolder() { ::JS_DestroyScript(mCx, mScript); }
2274 - private:
2275 -    JSContext *mCx;
2276 -    JSScript *mScript;
2277 -};
2278 -
2279  /**
2280   * PathifyURI transforms mozilla .js uris into useful zip paths
2281   * to make it makes it easier to manipulate startup cache entries
2282   * using standard zip tools.
2283   * Transformations applied:
2284   *  * jsloader/<scheme> prefix is used to group mozJSComponentLoader cache entries in
2285   *    a top-level zip directory.
2286   *  * In MOZ_OMNIJAR case resource:/// and resource://gre/ URIs refer to the same path
2287 @@ -880,17 +869,17 @@ PathifyURI(nsIURI *in, nsACString &out)
2288     out.Append(".bin");
2289     return NS_OK;
2290  }
2291  
2292  /* static */
2293  #ifdef MOZ_ENABLE_LIBXUL
2294  nsresult
2295  mozJSComponentLoader::ReadScript(StartupCache* cache, nsIURI *uri,
2296 -                                 JSContext *cx, JSScript **script)
2297 +                                 JSContext *cx, JSObject **scriptObj)
2298  {
2299      nsresult rv;
2300      
2301      nsCAutoString spec;
2302      rv = PathifyURI(uri, spec);
2303      NS_ENSURE_SUCCESS(rv, rv);
2304      
2305      nsAutoArrayPtr<char> buf;   
2306 @@ -902,37 +891,37 @@ mozJSComponentLoader::ReadScript(Startup
2307      }
2308  
2309      LOG(("Found %s in startupcache\n", spec.get()));
2310      nsCOMPtr<nsIObjectInputStream> ois;
2311      rv = NS_NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
2312      NS_ENSURE_SUCCESS(rv, rv);
2313      buf.forget();
2314  
2315 -    return ReadScriptFromStream(cx, ois, script);
2316 +    return ReadScriptFromStream(cx, ois, scriptObj);
2317  }
2318  
2319  nsresult
2320 -mozJSComponentLoader::WriteScript(StartupCache* cache, JSScript *script,
2321 +mozJSComponentLoader::WriteScript(StartupCache* cache, JSObject *scriptObj,
2322                                    nsIFile *component, nsIURI *uri, JSContext *cx)
2323  {
2324      nsresult rv;
2325  
2326      nsCAutoString spec;
2327      rv = PathifyURI(uri, spec);
2328      NS_ENSURE_SUCCESS(rv, rv);
2329  
2330      LOG(("Writing %s to startupcache\n", spec.get()));
2331      nsCOMPtr<nsIObjectOutputStream> oos;
2332      nsCOMPtr<nsIStorageStream> storageStream; 
2333      rv = NS_NewObjectOutputWrappedStorageStream(getter_AddRefs(oos),
2334                                                  getter_AddRefs(storageStream));
2335      NS_ENSURE_SUCCESS(rv, rv);
2336  
2337 -    rv = WriteScriptToStream(cx, script, oos);
2338 +    rv = WriteScriptToStream(cx, scriptObj, oos);
2339      oos->Close();
2340      NS_ENSURE_SUCCESS(rv, rv);
2341   
2342      nsAutoArrayPtr<char> buf;
2343      PRUint32 len;
2344      rv = NS_NewBufferFromStorageStream(storageStream, getter_Transfers(buf), 
2345                                         &len);
2346      NS_ENSURE_SUCCESS(rv, rv);
2347 @@ -1036,40 +1025,40 @@ mozJSComponentLoader::GlobalForLocation(
2348      // See: http://bugzilla.mozilla.org/show_bug.cgi?id=121438
2349  #ifdef XPCONNECT_STANDALONE
2350      localFile->GetNativePath(nativePath);
2351  #else
2352      rv = aURI->GetSpec(nativePath);
2353      NS_ENSURE_SUCCESS(rv, rv);
2354  #endif
2355  
2356 -    JSScript *script = nsnull;
2357 +    JSObject *scriptObj = nsnull;
2358  
2359  #ifdef MOZ_ENABLE_LIBXUL  
2360      // Before compiling the script, first check to see if we have it in
2361      // the startupcache.  Note: as a rule, startupcache errors are not fatal
2362      // to loading the script, since we can always slow-load.
2363      
2364      PRBool writeToCache = PR_FALSE;
2365      StartupCache* cache = StartupCache::GetSingleton();
2366  
2367      if (cache) {
2368 -        rv = ReadScript(cache, aURI, cx, &script);
2369 +        rv = ReadScript(cache, aURI, cx, &scriptObj);
2370          if (NS_SUCCEEDED(rv)) {
2371              LOG(("Successfully loaded %s from startupcache\n", nativePath.get()));
2372          } else {
2373              // This is ok, it just means the script is not yet in the
2374              // cache. Could mean that the cache was corrupted and got removed,
2375              // but either way we're going to write this out.
2376              writeToCache = PR_TRUE;
2377          }
2378      }
2379  #endif
2380  
2381 -    if (!script) {
2382 +    if (!scriptObj) {
2383          // The script wasn't in the cache , so compile it now.
2384          LOG(("Slow loading %s\n", nativePath.get()));
2385  
2386          // If |exception| is non-null, then our caller wants us to propagate
2387          // any exceptions out to our caller. Ensure that the engine doesn't
2388          // eagerly report the exception.
2389          uint32 oldopts = 0;
2390          if (exception) {
2391 @@ -1120,17 +1109,17 @@ mozJSComponentLoader::GlobalForLocation(
2392  
2393              char *buf = static_cast<char*>(PR_MemMap(map, 0, fileSize32));
2394              if (!buf) {
2395                  NS_WARNING("Failed to map file");
2396                  JS_SetOptions(cx, oldopts);
2397                  return NS_ERROR_FAILURE;
2398              }
2399  
2400 -            script = JS_CompileScriptForPrincipalsVersion(
2401 +            scriptObj = JS_CompileScriptForPrincipalsVersion(
2402                cx, global, jsPrincipals, buf, fileSize32, nativePath.get(), 1,
2403                JSVERSION_LATEST);
2404  
2405              PR_MemUnmap(buf, fileSize32);
2406  
2407  #else  /* HAVE_PR_MEMMAP */
2408  
2409              /**
2410 @@ -1176,78 +1165,73 @@ mozJSComponentLoader::GlobalForLocation(
2411  
2412              /* read the file in one swoop */
2413              rv = scriptStream->Read(buf, len, &bytesRead);
2414              if (bytesRead != len)
2415                  return NS_BASE_STREAM_OSERROR;
2416  
2417              buf[len] = '\0';
2418  
2419 -            script = JS_CompileScriptForPrincipalsVersion(
2420 +            scriptObj = JS_CompileScriptForPrincipalsVersion(
2421                cx, global, jsPrincipals, buf, bytesRead, nativePath.get(), 1,
2422                JSVERSION_LATEST);
2423          }
2424          // Propagate the exception, if one exists. Also, don't leave the stale
2425          // exception on this context.
2426 -        // NB: The caller must stick exception into a rooted slot (probably on
2427 -        // its context) as soon as possible to avoid GC hazards.
2428          if (exception) {
2429              JS_SetOptions(cx, oldopts);
2430 -            if (!script) {
2431 +            if (!scriptObj) {
2432                  JS_GetPendingException(cx, exception);
2433                  JS_ClearPendingException(cx);
2434              }
2435          }
2436      }
2437  
2438 -    if (!script) {
2439 +    if (!scriptObj) {
2440  #ifdef DEBUG_shaver_off
2441          fprintf(stderr, "mJCL: script compilation of %s FAILED\n",
2442                  nativePath.get());
2443  #endif
2444          return NS_ERROR_FAILURE;
2445      }
2446  
2447 -    // Ensure that we clean up the script on return.
2448 -    JSScriptHolder scriptHolder(cx, script);
2449 -
2450      // Flag this script as a system script
2451      // FIXME: BUG 346139: We actually want to flag this exact filename, not
2452      // anything that starts with this filename... Maybe we need a way to do
2453      // that?  On the other hand, the fact that this is in our components dir
2454      // means that if someone snuck a malicious file into this dir we're screwed
2455      // anyway...  So maybe flagging as a prefix is fine.
2456      xpc->FlagSystemFilenamePrefix(nativePath.get(), PR_TRUE);
2457  
2458  #ifdef DEBUG_shaver_off
2459      fprintf(stderr, "mJCL: compiled JS component %s\n",
2460              nativePath.get());
2461  #endif
2462  
2463  #ifdef MOZ_ENABLE_LIBXUL
2464      if (writeToCache) {
2465          // We successfully compiled the script, so cache it. 
2466 -        rv = WriteScript(cache, script, aComponentFile, aURI, cx);
2467 +        rv = WriteScript(cache, scriptObj, aComponentFile, aURI, cx);
2468  
2469          // Don't treat failure to write as fatal, since we might be working
2470          // with a read-only cache.
2471          if (NS_SUCCEEDED(rv)) {
2472              LOG(("Successfully wrote to cache\n"));
2473          } else {
2474              LOG(("Failed to write to cache\n"));
2475          }
2476      }
2477  #endif
2478  
2479      // Assign aGlobal here so that it's available to recursive imports.
2480      // See bug 384168.
2481      *aGlobal = global;
2482  
2483      jsval retval;
2484 -    if (!JS_ExecuteScriptVersion(cx, global, script, &retval, JSVERSION_LATEST)) {
2485 +    if (!JS_ExecuteScriptVersion(cx, global, scriptObj, &retval, JSVERSION_LATEST)) {
2486  #ifdef DEBUG_shaver_off
2487          fprintf(stderr, "mJCL: failed to execute %s\n", nativePath.get());
2488  #endif
2489          *aGlobal = nsnull;
2490          return NS_ERROR_FAILURE;
2491      }
2492  
2493      /* Freed when we remove from the table. */
2494 diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.h b/js/src/xpconnect/loader/mozJSComponentLoader.h
2495 --- a/js/src/xpconnect/loader/mozJSComponentLoader.h
2496 +++ b/js/src/xpconnect/loader/mozJSComponentLoader.h
2497 @@ -130,18 +130,18 @@ class mozJSComponentLoader : public mozi
2498      nsresult GlobalForLocation(nsILocalFile* aComponentFile,
2499                                 nsIURI *aComponent,
2500                                 JSObject **aGlobal,
2501                                 char **location,
2502                                 jsval *exception);
2503  
2504  #ifdef MOZ_ENABLE_LIBXUL
2505      nsresult ReadScript(StartupCache *cache, nsIURI *uri, 
2506 -                        JSContext *cx, JSScript **script);
2507 -    nsresult WriteScript(StartupCache *cache, JSScript *script,
2508 +                        JSContext *cx, JSObject **scriptObj);
2509 +    nsresult WriteScript(StartupCache *cache, JSObject *scriptObj,
2510                           nsIFile *component, nsIURI *uri, JSContext *cx);
2511  #endif
2512  
2513      nsCOMPtr<nsIComponentManager> mCompMgr;
2514      nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
2515      nsCOMPtr<nsIThreadJSContextStack> mContextStack;
2516  #ifndef XPCONNECT_STANDALONE
2517      nsCOMPtr<nsIPrincipal> mSystemPrincipal;
2518 diff --git a/js/src/xpconnect/shell/xpcshell.cpp b/js/src/xpconnect/shell/xpcshell.cpp
2519 --- a/js/src/xpconnect/shell/xpcshell.cpp
2520 +++ b/js/src/xpconnect/shell/xpcshell.cpp
2521 @@ -457,57 +457,47 @@ Dump(JSContext *cx, uintN argc, jsval *v
2522      fputs(bytes.ptr(), gOutFile);
2523      fflush(gOutFile);
2524      return JS_TRUE;
2525  }
2526  
2527  static JSBool
2528  Load(JSContext *cx, uintN argc, jsval *vp)
2529  {
2530 -    uintN i;
2531 -    JSString *str;
2532 -    JSScript *script;
2533 -    JSBool ok;
2534 -    jsval result;
2535 -    FILE *file;
2536 -
2537      JSObject *obj = JS_THIS_OBJECT(cx, vp);
2538      if (!obj)
2539 -        return JS_FALSE;
2540 +        return false;
2541  
2542      jsval *argv = JS_ARGV(cx, vp);
2543 -    for (i = 0; i < argc; i++) {
2544 -        str = JS_ValueToString(cx, argv[i]);
2545 +    for (uintN i = 0; i < argc; i++) {
2546 +        JSString *str = JS_ValueToString(cx, argv[i]);
2547          if (!str)
2548 -            return JS_FALSE;
2549 +            return false;
2550          argv[i] = STRING_TO_JSVAL(str);
2551          JSAutoByteString filename(cx, str);
2552          if (!filename)
2553 -            return JS_FALSE;
2554 -        file = fopen(filename.ptr(), "r");
2555 +            return false;
2556 +        FILE *file = fopen(filename.ptr(), "r");
2557          if (!file) {
2558              JS_ReportError(cx, "cannot open file '%s' for reading",
2559                             filename.ptr());
2560 -            return JS_FALSE;
2561 +            return false;
2562          }
2563 -        script = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(),
2564 -                                                   file, gJSPrincipals);
2565 +        JSObject *scriptObj = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(),
2566 +                                                                file, gJSPrincipals);
2567          fclose(file);
2568 -        if (!script)
2569 -            return JS_FALSE;
2570 +        if (!scriptObj)
2571 +            return false;
2572  
2573 -        ok = !compileOnly
2574 -             ? JS_ExecuteScript(cx, obj, script, &result)
2575 -             : JS_TRUE;
2576 -        JS_DestroyScript(cx, script);
2577 -        if (!ok)
2578 -            return JS_FALSE;
2579 +        jsval result;
2580 +        if (!compileOnly && !JS_ExecuteScript(cx, obj, scriptObj, &result))
2581 +            return false;
2582      }
2583      JS_SET_RVAL(cx, vp, JSVAL_VOID);
2584 -    return JS_TRUE;
2585 +    return true;
2586  }
2587  
2588  static JSBool
2589  Version(JSContext *cx, uintN argc, jsval *vp)
2590  {
2591      if (argc > 0 && JSVAL_IS_INT(JS_ARGV(cx, vp)[0]))
2592          JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(JSVAL_TO_INT(JS_ARGV(cx, vp)[0])))));
2593      else
2594 @@ -1041,17 +1031,17 @@ my_GetErrorMessage(void *userRef, const 
2595          else
2596              return NULL;
2597  }
2598  
2599  static void
2600  ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
2601              JSBool forceTTY)
2602  {
2603 -    JSScript *script;
2604 +    JSObject *scriptObj;
2605      jsval result;
2606      int lineno, startline;
2607      JSBool ok, hitEOF;
2608      char *bufp, buffer[4096];
2609      JSString *str;
2610  
2611      if (forceTTY) {
2612          file = stdin;
2613 @@ -1074,24 +1064,21 @@ ProcessFile(JSContext *cx, JSObject *obj
2614              while((ch = fgetc(file)) != EOF) {
2615                  if(ch == '\n' || ch == '\r')
2616                      break;
2617              }
2618          }
2619          ungetc(ch, file);
2620          DoBeginRequest(cx);
2621  
2622 -        script = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
2623 -                                                   gJSPrincipals);
2624 +        scriptObj = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
2625 +                                                      gJSPrincipals);
2626  
2627 -        if (script) {
2628 -            if (!compileOnly)
2629 -                (void)JS_ExecuteScript(cx, obj, script, &result);
2630 -            JS_DestroyScript(cx, script);
2631 -        }
2632 +        if (scriptObj && !compileOnly)
2633 +            (void)JS_ExecuteScript(cx, obj, scriptObj, &result);
2634          DoEndRequest(cx);
2635  
2636          return;
2637      }
2638  
2639      /* It's an interactive filehandle; drop into read-eval-print loop. */
2640      lineno = 1;
2641      hitEOF = JS_FALSE;
2642 @@ -1113,36 +1100,35 @@ ProcessFile(JSContext *cx, JSObject *obj
2643              }
2644              bufp += strlen(bufp);
2645              lineno++;
2646          } while (!JS_BufferIsCompilableUnit(cx, obj, buffer, strlen(buffer)));
2647  
2648          DoBeginRequest(cx);
2649          /* Clear any pending exception from previous failed compiles.  */
2650          JS_ClearPendingException(cx);
2651 -        script = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
2652 -                                               strlen(buffer), "typein", startline);
2653 -        if (script) {
2654 +        scriptObj = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
2655 +                                                  strlen(buffer), "typein", startline);
2656 +        if (scriptObj) {
2657              JSErrorReporter older;
2658  
2659              if (!compileOnly) {
2660 -                ok = JS_ExecuteScript(cx, obj, script, &result);
2661 +                ok = JS_ExecuteScript(cx, obj, scriptObj, &result);
2662                  if (ok && result != JSVAL_VOID) {
2663                      /* Suppress error reports from JS_ValueToString(). */
2664                      older = JS_SetErrorReporter(cx, NULL);
2665                      str = JS_ValueToString(cx, result);
2666                      JS_SetErrorReporter(cx, older);
2667                      JSAutoByteString bytes;
2668                      if (str && bytes.encode(cx, str))
2669                          fprintf(gOutFile, "%s\n", bytes.ptr());
2670                      else
2671                          ok = JS_FALSE;
2672                  }
2673              }
2674 -            JS_DestroyScript(cx, script);
2675          }
2676          DoEndRequest(cx);
2677      } while (!hitEOF && !gQuitting);
2678  
2679      fprintf(gOutFile, "\n");
2680  }
2681  
2682  static void
2683 diff --git a/js/src/xpconnect/src/xpcstack.cpp b/js/src/xpconnect/src/xpcstack.cpp
2684 --- a/js/src/xpconnect/src/xpcstack.cpp
2685 +++ b/js/src/xpconnect/src/xpcstack.cpp
2686 @@ -155,21 +155,21 @@ XPCJSStackFrame::CreateStack(JSContext* 
2687              else
2688                  self->mLanguage = nsIProgrammingLanguage::JAVASCRIPT;
2689              if(self->IsJSFrame())
2690              {
2691                  JSScript* script = JS_GetFrameScript(cx, fp);
2692                  jsbytecode* pc = JS_GetFramePC(cx, fp);
2693                  if(script && pc)
2694                  {
2695 -                    JSAutoEnterCompartment ac;
2696 +                    JS::AutoEnterScriptCompartment ac;
2697                      if(ac.enter(cx, script))
2698 -                     {
2699 -                         const char* filename = JS_GetScriptFilename(cx, script);
2700 -                         if(filename)
2701 +                    {
2702 +                        const char* filename = JS_GetScriptFilename(cx, script);
2703 +                        if(filename)
2704                          {
2705                              self->mFilename = (char*)
2706                                      nsMemory::Clone(filename,
2707                                              sizeof(char)*(strlen(filename)+1));
2708                          }
2709  
2710                          self->mLineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
2711  
2712 diff --git a/js/src/xpconnect/tests/TestXPC.cpp b/js/src/xpconnect/tests/TestXPC.cpp
2713 --- a/js/src/xpconnect/tests/TestXPC.cpp
2714 +++ b/js/src/xpconnect/tests/TestXPC.cpp
2715 @@ -94,42 +94,34 @@ Print(JSContext *cx, uintN argc, jsval *
2716      return true;
2717  }
2718  
2719  static JSBool
2720  Load(JSContext *cx, uintN argc, jsval *vp)
2721  {
2722      uintN i;
2723      JSString *str;
2724 -    JSScript *script;
2725 -    JSBool ok;
2726      jsval result;
2727  
2728      JSObject *obj = JS_THIS_OBJECT(cx, vp);
2729      if (!obj)
2730          return JS_FALSE;
2731  
2732      jsval *argv = JS_ARGV(cx, vp);
2733      for (i = 0; i < argc; i++) {
2734          str = JS_ValueToString(cx, argv[i]);
2735          if (!str)
2736              return JS_FALSE;
2737          argv[i] = STRING_TO_JSVAL(str);
2738          JSAutoByteString filename(cx, str);
2739          if (!filename)
2740              return false;
2741 -        script = JS_CompileFile(cx, obj, filename.ptr());
2742 -        if (!script)
2743 -            ok = JS_FALSE;
2744 -        else {
2745 -            ok = JS_ExecuteScript(cx, obj, script, &result);
2746 -            JS_DestroyScript(cx, script);
2747 -        }
2748 -        if (!ok)
2749 -            return JS_FALSE;
2750 +        JSObject *scriptObj = JS_CompileFile(cx, obj, filename.ptr());
2751 +        if (!scriptObj || !JS_ExecuteScript(cx, obj, scriptObj, &result))
2752 +            return false;
2753      }
2754      JS_SET_RVAL(cx, vp, JSVAL_VOID);
2755      return JS_TRUE;
2756  }
2757  
2758  static JSFunctionSpec glob_functions[] = {
2759      {"print",           Print,          0,0},
2760      {"load",            Load,           1,0},