Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testForceLexicalInitialization.cpp
blobbe0468897d11834337e1f823336cc06437b1862b
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 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "jsfriendapi.h"
9 #include "jsapi-tests/tests.h"
10 #include "vm/EnvironmentObject.h"
12 BEGIN_TEST(testForceLexicalInitialization) {
13 // Attach an uninitialized lexical to a scope and ensure that it's
14 // set to undefined
15 JS::Rooted<js::GlobalObject*> g(cx, cx->global());
16 JS::Rooted<js::GlobalLexicalEnvironmentObject*> env(
17 cx, js::GlobalLexicalEnvironmentObject::create(cx, g));
19 JS::RootedValue uninitialized(cx, JS::MagicValue(JS_UNINITIALIZED_LEXICAL));
20 JS::Rooted<js::PropertyName*> name(cx,
21 Atomize(cx, "foopi", 4)->asPropertyName());
22 JS::RootedId id(cx, NameToId(name));
23 unsigned attrs = JSPROP_ENUMERATE | JSPROP_PERMANENT;
25 CHECK(NativeDefineDataProperty(cx, env, id, uninitialized, attrs));
27 // Verify that "foopi" is uninitialized
28 const JS::Value v = env->getSlot(env->lookup(cx, id)->slot());
29 CHECK(v.isMagic(JS_UNINITIALIZED_LEXICAL));
31 ForceLexicalInitialization(cx, env);
33 // Verify that "foopi" has been initialized to undefined
34 const JS::Value v2 = env->getSlot(env->lookup(cx, id)->slot());
35 CHECK(v2.isUndefined());
37 return true;
39 END_TEST(testForceLexicalInitialization)