michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: static bool michael@0: GlobalEnumerate(JSContext *cx, JS::Handle obj) michael@0: { michael@0: return JS_EnumerateStandardClasses(cx, obj); michael@0: } michael@0: michael@0: static bool michael@0: GlobalResolve(JSContext *cx, JS::Handle obj, JS::Handle id) michael@0: { michael@0: bool resolved = false; michael@0: return JS_ResolveStandardClass(cx, obj, id, &resolved); michael@0: } michael@0: michael@0: BEGIN_TEST(testRedefineGlobalEval) michael@0: { michael@0: static const JSClass cls = { michael@0: "global", JSCLASS_GLOBAL_FLAGS, michael@0: JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, michael@0: GlobalEnumerate, GlobalResolve, JS_ConvertStub, michael@0: nullptr, nullptr, nullptr, nullptr, michael@0: JS_GlobalObjectTraceHook michael@0: }; michael@0: michael@0: /* Create the global object. */ michael@0: JS::CompartmentOptions options; michael@0: options.setVersion(JSVERSION_LATEST); michael@0: JS::Rooted g(cx, JS_NewGlobalObject(cx, &cls, nullptr, JS::FireOnNewGlobalHook, options)); michael@0: if (!g) michael@0: return false; michael@0: michael@0: JSAutoCompartment ac(cx, g); michael@0: JS::Rooted v(cx); michael@0: CHECK(JS_GetProperty(cx, g, "Object", &v)); michael@0: michael@0: static const char data[] = "Object.defineProperty(this, 'eval', { configurable: false });"; michael@0: CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, &v)); michael@0: michael@0: return true; michael@0: } michael@0: END_TEST(testRedefineGlobalEval)