|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
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/. */ |
|
7 |
|
8 #include "jsapi-tests/tests.h" |
|
9 |
|
10 static bool |
|
11 GlobalEnumerate(JSContext *cx, JS::Handle<JSObject*> obj) |
|
12 { |
|
13 return JS_EnumerateStandardClasses(cx, obj); |
|
14 } |
|
15 |
|
16 static bool |
|
17 GlobalResolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id) |
|
18 { |
|
19 bool resolved = false; |
|
20 return JS_ResolveStandardClass(cx, obj, id, &resolved); |
|
21 } |
|
22 |
|
23 BEGIN_TEST(testRedefineGlobalEval) |
|
24 { |
|
25 static const JSClass cls = { |
|
26 "global", JSCLASS_GLOBAL_FLAGS, |
|
27 JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, |
|
28 GlobalEnumerate, GlobalResolve, JS_ConvertStub, |
|
29 nullptr, nullptr, nullptr, nullptr, |
|
30 JS_GlobalObjectTraceHook |
|
31 }; |
|
32 |
|
33 /* Create the global object. */ |
|
34 JS::CompartmentOptions options; |
|
35 options.setVersion(JSVERSION_LATEST); |
|
36 JS::Rooted<JSObject*> g(cx, JS_NewGlobalObject(cx, &cls, nullptr, JS::FireOnNewGlobalHook, options)); |
|
37 if (!g) |
|
38 return false; |
|
39 |
|
40 JSAutoCompartment ac(cx, g); |
|
41 JS::Rooted<JS::Value> v(cx); |
|
42 CHECK(JS_GetProperty(cx, g, "Object", &v)); |
|
43 |
|
44 static const char data[] = "Object.defineProperty(this, 'eval', { configurable: false });"; |
|
45 CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, &v)); |
|
46 |
|
47 return true; |
|
48 } |
|
49 END_TEST(testRedefineGlobalEval) |