| 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/. */ |
| 7 |
|
| 8 |
#include "js/Object.h" // JS::GetClass |
| 9 |
#include "js/PropertyAndElement.h" // JS_DefineProperty |
| 10 |
#include "jsapi-tests/tests.h" |
| 11 |
|
| 12 |
BEGIN_TEST(testSetProperty_InheritedGlobalSetter) { |
| 13 |
// This is a JSAPI test because jsapi-test globals can be set up to not have |
| 14 |
// a resolve hook and therefore can use the property cache in some cases |
| 15 |
// where the shell can't. |
| 16 |
MOZ_RELEASE_ASSERT(!JS::GetClass(global)->getResolve()); |
| 17 |
|
| 18 |
CHECK(JS::InitRealmStandardClasses(cx)); |
| 19 |
|
| 20 |
CHECK(JS_DefineProperty(cx, global, "HOTLOOP", 8, 0)); |
| 21 |
EXEC( |
| 22 |
"var n = 0;\n" |
| 23 |
"var global = this;\n" |
| 24 |
"function f() { n++; }\n" |
| 25 |
"Object.defineProperty(Object.prototype, 'x', {set: f});\n" |
| 26 |
"for (var i = 0; i < HOTLOOP; i++)\n" |
| 27 |
" global.x = i;\n"); |
| 28 |
EXEC( |
| 29 |
"if (n != HOTLOOP)\n" |
| 30 |
" throw 'FAIL';\n"); |
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
const JSClass* getGlobalClass(void) override { |
| 35 |
static const JSClassOps noResolveGlobalClassOps = { |
| 36 |
nullptr, // addProperty |
| 37 |
nullptr, // delProperty |
| 38 |
nullptr, // enumerate |
| 39 |
nullptr, // newEnumerate |
| 40 |
nullptr, // resolve |
| 41 |
nullptr, // mayResolve |
| 42 |
nullptr, // finalize |
| 43 |
nullptr, // call |
| 44 |
nullptr, // construct |
| 45 |
JS_GlobalObjectTraceHook, // trace |
| 46 |
}; |
| 47 |
|
| 48 |
static const JSClass noResolveGlobalClass = { |
| 49 |
"testSetProperty_InheritedGlobalSetter_noResolveGlobalClass", |
| 50 |
JSCLASS_GLOBAL_FLAGS, |
| 51 |
&noResolveGlobalClassOps, |
| 52 |
}; |
| 53 |
|
| 54 |
return &noResolveGlobalClass; |
| 55 |
} |
| 56 |
END_TEST(testSetProperty_InheritedGlobalSetter) |