summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testDebugger.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testDebugger.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testDebugger.cpp')
-rw-r--r--js/src/jsapi-tests/testDebugger.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testDebugger.cpp b/js/src/jsapi-tests/testDebugger.cpp
new file mode 100644
index 000000000..e03e3ab16
--- /dev/null
+++ b/js/src/jsapi-tests/testDebugger.cpp
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "jscntxt.h"
+
+#include "jsapi-tests/tests.h"
+
+using namespace js;
+
+BEGIN_TEST(testDebugger_newScriptHook)
+{
+ // Test that top-level indirect eval fires the newScript hook.
+ CHECK(JS_DefineDebuggerObject(cx, global));
+ JS::CompartmentOptions options;
+ JS::RootedObject g(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
+ JS::FireOnNewGlobalHook, options));
+ CHECK(g);
+ {
+ JSAutoCompartment ae(cx, g);
+ CHECK(JS_InitStandardClasses(cx, g));
+ }
+
+ JS::RootedObject gWrapper(cx, g);
+ CHECK(JS_WrapObject(cx, &gWrapper));
+ JS::RootedValue v(cx, JS::ObjectValue(*gWrapper));
+ CHECK(JS_SetProperty(cx, global, "g", v));
+
+ EXEC("var dbg = Debugger(g);\n"
+ "var hits = 0;\n"
+ "dbg.onNewScript = function (s) {\n"
+ " hits += Number(s instanceof Debugger.Script);\n"
+ "};\n");
+
+ // Since g is a debuggee, g.eval should trigger newScript, regardless of
+ // what scope object we use to enter the compartment.
+ //
+ // Scripts are associated with the global where they're compiled, so we
+ // deliver them only to debuggers that are watching that particular global.
+ //
+ return testIndirectEval(g, "Math.abs(0)");
+}
+
+bool testIndirectEval(JS::HandleObject scope, const char* code)
+{
+ EXEC("hits = 0;");
+
+ {
+ JSAutoCompartment ae(cx, scope);
+ JSString* codestr = JS_NewStringCopyZ(cx, code);
+ CHECK(codestr);
+ JS::RootedValue arg(cx, JS::StringValue(codestr));
+ JS::RootedValue v(cx);
+ CHECK(JS_CallFunctionName(cx, scope, "eval", HandleValueArray(arg), &v));
+ }
+
+ JS::RootedValue hitsv(cx);
+ EVAL("hits", &hitsv);
+ CHECK(hitsv.isInt32(1));
+ return true;
+}
+END_TEST(testDebugger_newScriptHook)