Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "jsscript.h"
7 #include "jsapi-tests/tests.h"
9 BEGIN_TEST(testBug795104)
10 {
11 JS::CompileOptions opts(cx);
12 JS::CompartmentOptionsRef(cx->compartment()).setDiscardSource(true);
13 const size_t strLen = 60002;
14 char *s = static_cast<char *>(JS_malloc(cx, strLen));
15 CHECK(s);
16 s[0] = '"';
17 memset(s + 1, 'x', strLen - 2);
18 s[strLen - 1] = '"';
19 CHECK(JS::Evaluate(cx, global, opts, s, strLen));
20 CHECK(JS::CompileFunction(cx, global, opts, "f", 0, nullptr, s, strLen));
21 JS_free(cx, s);
23 return true;
24 }
25 END_TEST(testBug795104)
27 static const char *const simpleSource = "var x = 4;";
29 BEGIN_TEST(testScriptSourceReentrant)
30 {
31 JS::CompileOptions opts(cx);
32 bool match = false;
33 JS_SetNewScriptHook(rt, NewScriptHook, &match);
34 CHECK(JS::Evaluate(cx, global, opts, simpleSource, strlen(simpleSource)));
35 CHECK(match);
36 JS_SetNewScriptHook(rt, nullptr, nullptr);
38 return true;
39 }
41 static void
42 NewScriptHook(JSContext *cx, const char *fn, unsigned lineno,
43 JSScript *script, JSFunction *fun, void *data)
44 {
45 if (!JS_StringEqualsAscii(cx, script->sourceData(cx), simpleSource, (bool *)data))
46 *((bool *)data) = false;
47 }
48 END_TEST(testScriptSourceReentrant)