summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testJSEvaluateScript.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jsapi-tests/testJSEvaluateScript.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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)