diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 2991bf2a170..0c9daeb3292 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1343,7 +1343,8 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj) /* Define a top-level property 'undefined' with the undefined value. */ atom = cx->runtime->atomState.typeAtoms[JSTYPE_VOID]; if (!obj->defineProperty(cx, ATOM_TO_JSID(atom), JSVAL_VOID, - JS_PropertyStub, JS_PropertyStub, JSPROP_PERMANENT)) { + JS_PropertyStub, JS_PropertyStub, + JSPROP_PERMANENT | JSPROP_READONLY)) { return JS_FALSE; } @@ -1550,7 +1551,7 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id, *resolved = JS_TRUE; return obj->defineProperty(cx, ATOM_TO_JSID(atom), JSVAL_VOID, JS_PropertyStub, JS_PropertyStub, - JSPROP_PERMANENT); + JSPROP_PERMANENT | JSPROP_READONLY); } /* Try for class constructors/prototypes named by well-known atoms. */ diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 43dc6874b2f..6256e1016eb 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -790,14 +790,15 @@ js_InitNumberClass(JSContext *cx, JSObject *obj) /* ECMA 15.1.1.1 */ rt = cx->runtime; - if (!JS_DefineProperty(cx, obj, js_NaN_str, rt->NaNValue, - NULL, NULL, JSPROP_PERMANENT)) { + if (!JS_DefineProperty(cx, obj, js_NaN_str, rt->NaNValue, JS_PropertyStub, JS_PropertyStub, + JSPROP_PERMANENT | JSPROP_READONLY)) { return NULL; } /* ECMA 15.1.1.2 */ if (!JS_DefineProperty(cx, obj, js_Infinity_str, rt->positiveInfinityValue, - NULL, NULL, JSPROP_PERMANENT)) { + JS_PropertyStub, JS_PropertyStub, + JSPROP_PERMANENT | JSPROP_READONLY)) { return NULL; } return proto; diff --git a/js/src/tests/ecma_5/misc/browser.js b/js/src/tests/ecma_5/misc/browser.js new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/js/src/tests/ecma_5/misc/browser.js @@ -0,0 +1 @@ + diff --git a/js/src/tests/ecma_5/misc/global-numeric-properties.js b/js/src/tests/ecma_5/misc/global-numeric-properties.js new file mode 100644 index 00000000000..1a85945dc7a --- /dev/null +++ b/js/src/tests/ecma_5/misc/global-numeric-properties.js @@ -0,0 +1,60 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +var gTestfile = 'global-numeric-properties.js'; +//----------------------------------------------------------------------------- +var BUGNUMBER = 537863; +var summary = + 'undefined, Infinity, and NaN global properties should not be writable'; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var desc, old, error; +var global = this; + +var names = ["NaN", "Infinity", "undefined"]; + +for (var i = 0; i < names.length; i++) +{ + var name = names[i]; + desc = Object.getOwnPropertyDescriptor(global, name); + assertEq(desc !== undefined, true, name + " should be present"); + assertEq(desc.enumerable, false, name + " should not be enumerable"); + assertEq(desc.configurable, false, name + " should not be configurable"); + assertEq(desc.writable, false, name + " should not be writable"); + + old = global[name]; + global[name] = 17; + assertEq(global[name], old, name + " changed on setting?"); + + error = "before"; + try + { + throw new TypeError("SpiderMonkey doesn't currently implement " + + "strict-mode throwing when setting a readonly " + + "property, not running this bit of test for now; " + + "see bug 537873"); + + (function() { "use strict"; global[name] = 42; error = "didn't throw"; })(); + } + catch (e) + { + if (e instanceof TypeError) + error = "typeerror"; + else + error = "bad exception: " + e; + } + assertEq(error, "typeerror", "wrong strict mode error setting " + name); +} + +/******************************************************************************/ + +reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/ecma_5/misc/jstests.list b/js/src/tests/ecma_5/misc/jstests.list new file mode 100644 index 00000000000..1e15a365f3b --- /dev/null +++ b/js/src/tests/ecma_5/misc/jstests.list @@ -0,0 +1,2 @@ +url-prefix ../../jsreftest.html?test=ecma_5/misc/ +script global-numeric-properties.js diff --git a/js/src/tests/ecma_5/misc/shell.js b/js/src/tests/ecma_5/misc/shell.js new file mode 100644 index 00000000000..66091967809 --- /dev/null +++ b/js/src/tests/ecma_5/misc/shell.js @@ -0,0 +1 @@ +gTestsubsuite = 'misc';