Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "jsapi-tests/tests.h" |
michael@0 | 9 | |
michael@0 | 10 | static bool |
michael@0 | 11 | GlobalEnumerate(JSContext *cx, JS::Handle<JSObject*> obj) |
michael@0 | 12 | { |
michael@0 | 13 | return JS_EnumerateStandardClasses(cx, obj); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | static bool |
michael@0 | 17 | GlobalResolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id) |
michael@0 | 18 | { |
michael@0 | 19 | bool resolved = false; |
michael@0 | 20 | return JS_ResolveStandardClass(cx, obj, id, &resolved); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | BEGIN_TEST(testRedefineGlobalEval) |
michael@0 | 24 | { |
michael@0 | 25 | static const JSClass cls = { |
michael@0 | 26 | "global", JSCLASS_GLOBAL_FLAGS, |
michael@0 | 27 | JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, |
michael@0 | 28 | GlobalEnumerate, GlobalResolve, JS_ConvertStub, |
michael@0 | 29 | nullptr, nullptr, nullptr, nullptr, |
michael@0 | 30 | JS_GlobalObjectTraceHook |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | /* Create the global object. */ |
michael@0 | 34 | JS::CompartmentOptions options; |
michael@0 | 35 | options.setVersion(JSVERSION_LATEST); |
michael@0 | 36 | JS::Rooted<JSObject*> g(cx, JS_NewGlobalObject(cx, &cls, nullptr, JS::FireOnNewGlobalHook, options)); |
michael@0 | 37 | if (!g) |
michael@0 | 38 | return false; |
michael@0 | 39 | |
michael@0 | 40 | JSAutoCompartment ac(cx, g); |
michael@0 | 41 | JS::Rooted<JS::Value> v(cx); |
michael@0 | 42 | CHECK(JS_GetProperty(cx, g, "Object", &v)); |
michael@0 | 43 | |
michael@0 | 44 | static const char data[] = "Object.defineProperty(this, 'eval', { configurable: false });"; |
michael@0 | 45 | CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, &v)); |
michael@0 | 46 | |
michael@0 | 47 | return true; |
michael@0 | 48 | } |
michael@0 | 49 | END_TEST(testRedefineGlobalEval) |