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