Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testJSEvaluateScript.cpp
blob1dfc9ea3cb5f55467af360b4836f42cffd5cc398
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
5 #include "js/CompilationAndEvaluation.h"
6 #include "js/PropertyAndElement.h" // JS_AlreadyHasOwnProperty, JS_HasProperty
7 #include "js/SourceText.h"
8 #include "jsapi-tests/tests.h"
9 #include "util/Text.h"
11 BEGIN_TEST(testJSEvaluateScript) {
12 JS::RootedObject obj(cx, JS_NewPlainObject(cx));
13 CHECK(obj);
15 static const char16_t src[] = u"var x = 5;";
17 JS::RootedValue retval(cx);
18 JS::CompileOptions opts(cx);
19 JS::RootedObjectVector scopeChain(cx);
20 CHECK(scopeChain.append(obj));
22 JS::SourceText<char16_t> srcBuf;
23 CHECK(srcBuf.init(cx, src, js_strlen(src), JS::SourceOwnership::Borrowed));
25 CHECK(JS::Evaluate(cx, scopeChain, opts.setFileAndLine(__FILE__, __LINE__),
26 srcBuf, &retval));
28 bool hasProp = true;
29 CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
30 CHECK(hasProp);
32 hasProp = false;
33 CHECK(JS_HasProperty(cx, global, "x", &hasProp));
34 CHECK(!hasProp);
36 return true;
38 END_TEST(testJSEvaluateScript)