mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
1317387: The intrinsic %ThrowTypeError% function should be frozen.
This commit is contained in:
parent
e3244802ec
commit
c956643d36
2 changed files with 38 additions and 0 deletions
|
|
@ -861,6 +861,28 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key)
|
||||||
if (!throwTypeError || !PreventExtensions(cx, throwTypeError))
|
if (!throwTypeError || !PreventExtensions(cx, throwTypeError))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
// The "length" property of %ThrowTypeError% is non-configurable, adjust
|
||||||
|
// the default property attributes accordingly.
|
||||||
|
Rooted<PropertyDescriptor> nonConfigurableDesc(cx);
|
||||||
|
nonConfigurableDesc.setAttributes(JSPROP_PERMANENT | JSPROP_IGNORE_READONLY |
|
||||||
|
JSPROP_IGNORE_ENUMERATE | JSPROP_IGNORE_VALUE);
|
||||||
|
|
||||||
|
RootedId lengthId(cx, NameToId(cx->names().length));
|
||||||
|
ObjectOpResult lengthResult;
|
||||||
|
if (!NativeDefineProperty(cx, throwTypeError, lengthId, nonConfigurableDesc, lengthResult))
|
||||||
|
return nullptr;
|
||||||
|
MOZ_ASSERT(lengthResult);
|
||||||
|
|
||||||
|
// Non-standard: Also change "name" to non-configurable. ECMAScript defines
|
||||||
|
// %ThrowTypeError% as an anonymous function, i.e. it shouldn't actually
|
||||||
|
// get an own "name" property. To be consistent with other built-in,
|
||||||
|
// anonymous functions, we don't delete %ThrowTypeError%'s "name" property.
|
||||||
|
RootedId nameId(cx, NameToId(cx->names().name));
|
||||||
|
ObjectOpResult nameResult;
|
||||||
|
if (!NativeDefineProperty(cx, throwTypeError, nameId, nonConfigurableDesc, nameResult))
|
||||||
|
return nullptr;
|
||||||
|
MOZ_ASSERT(nameResult);
|
||||||
|
|
||||||
self->setThrowTypeError(throwTypeError);
|
self->setThrowTypeError(throwTypeError);
|
||||||
|
|
||||||
return functionProto;
|
return functionProto;
|
||||||
|
|
|
||||||
16
js/src/tests/ecma_6/Function/throw-type-error.js
Normal file
16
js/src/tests/ecma_6/Function/throw-type-error.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Any copyright is dedicated to the Public Domain.
|
||||||
|
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
|
||||||
|
const ThrowTypeError = function(){
|
||||||
|
"use strict";
|
||||||
|
return Object.getOwnPropertyDescriptor(arguments, "callee").get;
|
||||||
|
}();
|
||||||
|
|
||||||
|
assertDeepEq(Object.getOwnPropertyDescriptor(ThrowTypeError, "length"), {
|
||||||
|
value: 0, writable: false, enumerable: false, configurable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEq(Object.isFrozen(ThrowTypeError), true);
|
||||||
|
|
||||||
|
if (typeof reportCompare == "function")
|
||||||
|
reportCompare(true, true);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue