Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * |
michael@0 | 4 | * Test script cloning. |
michael@0 | 5 | */ |
michael@0 | 6 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 9 | |
michael@0 | 10 | #include "jsfriendapi.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "js/OldDebugAPI.h" |
michael@0 | 13 | #include "jsapi-tests/tests.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace js; |
michael@0 | 16 | |
michael@0 | 17 | static JSScript *foundScript = nullptr; |
michael@0 | 18 | |
michael@0 | 19 | static bool |
michael@0 | 20 | CheckEnclosing(JSContext *cx, unsigned argc, Value *vp) |
michael@0 | 21 | { |
michael@0 | 22 | CallArgs args = CallArgsFromVp(argc, vp); |
michael@0 | 23 | |
michael@0 | 24 | foundScript = js::GetOutermostEnclosingFunctionOfScriptedCaller(cx); |
michael@0 | 25 | |
michael@0 | 26 | args.rval().set(UndefinedValue()); |
michael@0 | 27 | return true; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | BEGIN_TEST(test_enclosingFunction) |
michael@0 | 31 | { |
michael@0 | 32 | CHECK(JS_DefineFunction(cx, global, "checkEnclosing", CheckEnclosing, 0, 0)); |
michael@0 | 33 | |
michael@0 | 34 | EXEC("checkEnclosing()"); |
michael@0 | 35 | CHECK(foundScript == nullptr); |
michael@0 | 36 | |
michael@0 | 37 | RootedFunction fun(cx); |
michael@0 | 38 | |
michael@0 | 39 | JS::CompileOptions options(cx); |
michael@0 | 40 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 41 | |
michael@0 | 42 | const char s1chars[] = "checkEnclosing()"; |
michael@0 | 43 | fun = JS_CompileFunction(cx, global, "s1", 0, nullptr, s1chars, |
michael@0 | 44 | strlen(s1chars), options); |
michael@0 | 45 | CHECK(fun); |
michael@0 | 46 | EXEC("s1()"); |
michael@0 | 47 | CHECK(foundScript == JS_GetFunctionScript(cx, fun)); |
michael@0 | 48 | |
michael@0 | 49 | const char s2chars[] = "return function() { checkEnclosing() }"; |
michael@0 | 50 | fun = JS_CompileFunction(cx, global, "s2", 0, nullptr, s2chars, |
michael@0 | 51 | strlen(s2chars), options); |
michael@0 | 52 | CHECK(fun); |
michael@0 | 53 | EXEC("s2()()"); |
michael@0 | 54 | CHECK(foundScript == JS_GetFunctionScript(cx, fun)); |
michael@0 | 55 | |
michael@0 | 56 | const char s3chars[] = "return function() { let (x) { function g() { checkEnclosing() } return g() } }"; |
michael@0 | 57 | fun = JS_CompileFunction(cx, global, "s3", 0, nullptr, s3chars, |
michael@0 | 58 | strlen(s3chars), options); |
michael@0 | 59 | CHECK(fun); |
michael@0 | 60 | EXEC("s3()()"); |
michael@0 | 61 | CHECK(foundScript == JS_GetFunctionScript(cx, fun)); |
michael@0 | 62 | |
michael@0 | 63 | return true; |
michael@0 | 64 | } |
michael@0 | 65 | END_TEST(test_enclosingFunction) |