1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
9 BEGIN_TEST(testXDR_bug506491)
12 "function makeClosure(s, name, value) {\n"
14 " return let (n = name, v = value) function () { return String(v); };\n"
16 "var f = makeClosure('0;', 'status', 'ok');\n";
19 JSObject *scriptObj = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
23 JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
25 CHECK(JS_XDRScriptObject(w, &scriptObj));
27 void *p = JS_XDRMemGetData(w, &nbytes);
29 void *frozen = JS_malloc(cx, nbytes);
31 memcpy(frozen, p, nbytes);
36 JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
37 JS_XDRMemSetData(r, frozen, nbytes);
38 CHECK(JS_XDRScriptObject(r, &scriptObj));
39 JS_XDRDestroy(r); // this frees `frozen`
43 CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
45 // try to break the Block object that is the parent of f
49 EVAL("f() === 'ok';\n", v2.addr());
50 jsvalRoot trueval(cx, JSVAL_TRUE);
51 CHECK_SAME(v2, trueval);
54 END_TEST(testXDR_bug506491)
56 BEGIN_TEST(testXDR_bug516827)
58 // compile an empty script
59 JSObject *scriptObj = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
63 JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
65 CHECK(JS_XDRScriptObject(w, &scriptObj));
67 void *p = JS_XDRMemGetData(w, &nbytes);
69 void *frozen = JS_malloc(cx, nbytes);
71 memcpy(frozen, p, nbytes);
76 JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
77 JS_XDRMemSetData(r, frozen, nbytes);
78 CHECK(JS_XDRScriptObject(r, &scriptObj));
79 JS_XDRDestroy(r); // this frees `frozen`
81 // execute with null result meaning no result wanted
82 CHECK(JS_ExecuteScript(cx, global, scriptObj, NULL));
85 END_TEST(testXDR_bug516827)