1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testFreshGlobalEvalRedefinition.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "jsapi-tests/tests.h" 1.12 + 1.13 +static bool 1.14 +GlobalEnumerate(JSContext *cx, JS::Handle<JSObject*> obj) 1.15 +{ 1.16 + return JS_EnumerateStandardClasses(cx, obj); 1.17 +} 1.18 + 1.19 +static bool 1.20 +GlobalResolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id) 1.21 +{ 1.22 + bool resolved = false; 1.23 + return JS_ResolveStandardClass(cx, obj, id, &resolved); 1.24 +} 1.25 + 1.26 +BEGIN_TEST(testRedefineGlobalEval) 1.27 +{ 1.28 + static const JSClass cls = { 1.29 + "global", JSCLASS_GLOBAL_FLAGS, 1.30 + JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 1.31 + GlobalEnumerate, GlobalResolve, JS_ConvertStub, 1.32 + nullptr, nullptr, nullptr, nullptr, 1.33 + JS_GlobalObjectTraceHook 1.34 + }; 1.35 + 1.36 + /* Create the global object. */ 1.37 + JS::CompartmentOptions options; 1.38 + options.setVersion(JSVERSION_LATEST); 1.39 + JS::Rooted<JSObject*> g(cx, JS_NewGlobalObject(cx, &cls, nullptr, JS::FireOnNewGlobalHook, options)); 1.40 + if (!g) 1.41 + return false; 1.42 + 1.43 + JSAutoCompartment ac(cx, g); 1.44 + JS::Rooted<JS::Value> v(cx); 1.45 + CHECK(JS_GetProperty(cx, g, "Object", &v)); 1.46 + 1.47 + static const char data[] = "Object.defineProperty(this, 'eval', { configurable: false });"; 1.48 + CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, &v)); 1.49 + 1.50 + return true; 1.51 +} 1.52 +END_TEST(testRedefineGlobalEval)