michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsscript.h" michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: BEGIN_TEST(testBug795104) michael@0: { michael@0: JS::CompileOptions opts(cx); michael@0: JS::CompartmentOptionsRef(cx->compartment()).setDiscardSource(true); michael@0: const size_t strLen = 60002; michael@0: char *s = static_cast(JS_malloc(cx, strLen)); michael@0: CHECK(s); michael@0: s[0] = '"'; michael@0: memset(s + 1, 'x', strLen - 2); michael@0: s[strLen - 1] = '"'; michael@0: CHECK(JS::Evaluate(cx, global, opts, s, strLen)); michael@0: CHECK(JS::CompileFunction(cx, global, opts, "f", 0, nullptr, s, strLen)); michael@0: JS_free(cx, s); michael@0: michael@0: return true; michael@0: } michael@0: END_TEST(testBug795104) michael@0: michael@0: static const char *const simpleSource = "var x = 4;"; michael@0: michael@0: BEGIN_TEST(testScriptSourceReentrant) michael@0: { michael@0: JS::CompileOptions opts(cx); michael@0: bool match = false; michael@0: JS_SetNewScriptHook(rt, NewScriptHook, &match); michael@0: CHECK(JS::Evaluate(cx, global, opts, simpleSource, strlen(simpleSource))); michael@0: CHECK(match); michael@0: JS_SetNewScriptHook(rt, nullptr, nullptr); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static void michael@0: NewScriptHook(JSContext *cx, const char *fn, unsigned lineno, michael@0: JSScript *script, JSFunction *fun, void *data) michael@0: { michael@0: if (!JS_StringEqualsAscii(cx, script->sourceData(cx), simpleSource, (bool *)data)) michael@0: *((bool *)data) = false; michael@0: } michael@0: END_TEST(testScriptSourceReentrant)