summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testJSEvaluateScript.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jsapi-tests/testJSEvaluateScript.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jsapi-tests/testJSEvaluateScript.cpp')
-rw-r--r--js/src/jsapi-tests/testJSEvaluateScript.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testJSEvaluateScript.cpp b/js/src/jsapi-tests/testJSEvaluateScript.cpp
new file mode 100644
index 0000000000..1dfc9ea3cb
--- /dev/null
+++ b/js/src/jsapi-tests/testJSEvaluateScript.cpp
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ */
+
+#include "js/CompilationAndEvaluation.h"
+#include "js/PropertyAndElement.h" // JS_AlreadyHasOwnProperty, JS_HasProperty
+#include "js/SourceText.h"
+#include "jsapi-tests/tests.h"
+#include "util/Text.h"
+
+BEGIN_TEST(testJSEvaluateScript) {
+ JS::RootedObject obj(cx, JS_NewPlainObject(cx));
+ CHECK(obj);
+
+ static const char16_t src[] = u"var x = 5;";
+
+ JS::RootedValue retval(cx);
+ JS::CompileOptions opts(cx);
+ JS::RootedObjectVector scopeChain(cx);
+ CHECK(scopeChain.append(obj));
+
+ JS::SourceText<char16_t> srcBuf;
+ CHECK(srcBuf.init(cx, src, js_strlen(src), JS::SourceOwnership::Borrowed));
+
+ CHECK(JS::Evaluate(cx, scopeChain, opts.setFileAndLine(__FILE__, __LINE__),
+ srcBuf, &retval));
+
+ bool hasProp = true;
+ CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
+ CHECK(hasProp);
+
+ hasProp = false;
+ CHECK(JS_HasProperty(cx, global, "x", &hasProp));
+ CHECK(!hasProp);
+
+ return true;
+}
+END_TEST(testJSEvaluateScript)