Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// This file relies on the fact that the following declarations have been made
|
|
|
|
// in runtime.js:
|
2012-02-20 13:48:24 +00:00
|
|
|
// var $Object = global.Object;
|
|
|
|
// var $Boolean = global.Boolean;
|
|
|
|
// var $Number = global.Number;
|
|
|
|
// var $Function = global.Function;
|
|
|
|
// var $Array = global.Array;
|
2008-10-03 07:14:31 +00:00
|
|
|
//
|
|
|
|
// in math.js:
|
2012-02-20 13:48:24 +00:00
|
|
|
// var $floor = MathFloor
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var $isNaN = GlobalIsNaN;
|
|
|
|
var $isFinite = GlobalIsFinite;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// Helper function used to install functions on objects.
|
|
|
|
function InstallFunctions(object, attributes, functions) {
|
2009-08-13 12:35:59 +00:00
|
|
|
if (functions.length >= 8) {
|
2009-08-18 09:47:45 +00:00
|
|
|
%OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
|
2009-08-13 12:35:59 +00:00
|
|
|
}
|
2008-10-03 18:00:28 +00:00
|
|
|
for (var i = 0; i < functions.length; i += 2) {
|
|
|
|
var key = functions[i];
|
|
|
|
var f = functions[i + 1];
|
|
|
|
%FunctionSetName(f, key);
|
2010-04-28 12:05:40 +00:00
|
|
|
%FunctionRemovePrototype(f);
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(object, key, f, attributes);
|
2011-05-30 13:49:22 +00:00
|
|
|
%SetNativeFlag(f);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2010-02-17 11:26:00 +00:00
|
|
|
%ToFastProperties(object);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-11-06 18:14:45 +00:00
|
|
|
|
2013-04-04 12:10:23 +00:00
|
|
|
// Helper function to install a getter-only accessor property.
|
2012-11-06 18:14:45 +00:00
|
|
|
function InstallGetter(object, name, getter) {
|
|
|
|
%FunctionSetName(getter, name);
|
|
|
|
%FunctionRemovePrototype(getter);
|
2014-06-27 13:48:37 +00:00
|
|
|
%DefineAccessorPropertyUnchecked(object, name, getter, null, DONT_ENUM);
|
2012-11-06 18:14:45 +00:00
|
|
|
%SetNativeFlag(getter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 12:10:23 +00:00
|
|
|
// Helper function to install a getter/setter accessor property.
|
|
|
|
function InstallGetterSetter(object, name, getter, setter) {
|
|
|
|
%FunctionSetName(getter, name);
|
|
|
|
%FunctionSetName(setter, name);
|
|
|
|
%FunctionRemovePrototype(getter);
|
|
|
|
%FunctionRemovePrototype(setter);
|
2014-06-27 13:48:37 +00:00
|
|
|
%DefineAccessorPropertyUnchecked(object, name, getter, setter, DONT_ENUM);
|
2013-04-04 12:10:23 +00:00
|
|
|
%SetNativeFlag(getter);
|
|
|
|
%SetNativeFlag(setter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-08 09:09:49 +00:00
|
|
|
// Helper function for installing constant properties on objects.
|
|
|
|
function InstallConstants(object, constants) {
|
|
|
|
if (constants.length >= 4) {
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(object, constants.length >> 1);
|
|
|
|
}
|
|
|
|
var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
|
|
|
|
for (var i = 0; i < constants.length; i += 2) {
|
|
|
|
var name = constants[i];
|
|
|
|
var k = constants[i + 1];
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(object, name, k, attributes);
|
2014-01-08 09:09:49 +00:00
|
|
|
}
|
|
|
|
%ToFastProperties(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-06 12:32:36 +00:00
|
|
|
// Prevents changes to the prototype of a built-in function.
|
2011-09-05 07:30:35 +00:00
|
|
|
// The "prototype" property of the function object is made non-configurable,
|
|
|
|
// and the prototype object is made non-extensible. The latter prevents
|
|
|
|
// changing the __proto__ property.
|
|
|
|
function SetUpLockedPrototype(constructor, fields, methods) {
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
var prototype = constructor.prototype;
|
|
|
|
// Install functions first, because this function is used to initialize
|
|
|
|
// PropertyDescriptor itself.
|
|
|
|
var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
|
|
|
|
if (property_count >= 4) {
|
|
|
|
%OptimizeObjectForAddingMultipleProperties(prototype, property_count);
|
|
|
|
}
|
|
|
|
if (fields) {
|
|
|
|
for (var i = 0; i < fields.length; i++) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(prototype, fields[i],
|
|
|
|
UNDEFINED, DONT_ENUM | DONT_DELETE);
|
2011-09-05 07:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < methods.length; i += 2) {
|
|
|
|
var key = methods[i];
|
|
|
|
var f = methods[i + 1];
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2011-09-05 07:30:35 +00:00
|
|
|
%SetNativeFlag(f);
|
|
|
|
}
|
2014-08-11 14:00:58 +00:00
|
|
|
%InternalSetPrototype(prototype, null);
|
2011-09-05 07:30:35 +00:00
|
|
|
%ToFastProperties(prototype);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.1.4
|
2008-10-03 18:00:28 +00:00
|
|
|
function GlobalIsNaN(number) {
|
2011-09-05 11:08:57 +00:00
|
|
|
if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
|
|
|
|
return NUMBER_IS_NAN(number);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.1.5
|
2008-10-03 18:00:28 +00:00
|
|
|
function GlobalIsFinite(number) {
|
2011-01-05 13:52:00 +00:00
|
|
|
if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
|
2011-09-05 11:08:57 +00:00
|
|
|
return NUMBER_IS_FINITE(number);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 - 15.1.2.2
|
2008-10-03 18:00:28 +00:00
|
|
|
function GlobalParseInt(string, radix) {
|
2011-02-22 11:21:15 +00:00
|
|
|
if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Some people use parseInt instead of Math.floor. This
|
|
|
|
// optimization makes parseInt on a Smi 12 times faster (60ns
|
|
|
|
// vs 800ns). The following optimization makes parseInt on a
|
|
|
|
// non-Smi number 9 times faster (230ns vs 2070ns). Together
|
|
|
|
// they make parseInt on a string 1.4% slower (274ns vs 270ns).
|
|
|
|
if (%_IsSmi(string)) return string;
|
2009-02-16 10:18:34 +00:00
|
|
|
if (IS_NUMBER(string) &&
|
2009-11-17 13:54:05 +00:00
|
|
|
((0.01 < string && string < 1e9) ||
|
|
|
|
(-1e9 < string && string < -0.01))) {
|
2009-02-16 10:18:34 +00:00
|
|
|
// Truncate number.
|
|
|
|
return string | 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-09-02 11:38:40 +00:00
|
|
|
string = TO_STRING_INLINE(string);
|
2011-06-28 12:31:42 +00:00
|
|
|
radix = radix | 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2011-09-02 11:38:40 +00:00
|
|
|
// The spec says ToString should be evaluated before ToInt32.
|
|
|
|
string = TO_STRING_INLINE(string);
|
2008-07-03 15:10:15 +00:00
|
|
|
radix = TO_INT32(radix);
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!(radix == 0 || (2 <= radix && radix <= 36))) {
|
2013-10-17 10:02:45 +00:00
|
|
|
return NAN;
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-09-02 11:38:40 +00:00
|
|
|
|
2010-08-27 11:47:12 +00:00
|
|
|
if (%_HasCachedArrayIndex(string) &&
|
|
|
|
(radix == 0 || radix == 10)) {
|
|
|
|
return %_GetCachedArrayIndex(string);
|
|
|
|
}
|
|
|
|
return %StringParseInt(string, radix);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 - 15.1.2.3
|
2008-10-03 18:00:28 +00:00
|
|
|
function GlobalParseFloat(string) {
|
2010-08-27 11:47:12 +00:00
|
|
|
string = TO_STRING_INLINE(string);
|
|
|
|
if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string);
|
|
|
|
return %StringParseFloat(string);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 15:01:41 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function GlobalEval(x) {
|
|
|
|
if (!IS_STRING(x)) return x;
|
|
|
|
|
2011-05-30 13:49:22 +00:00
|
|
|
// For consistency with JSC we require the global object passed to
|
|
|
|
// eval to be the global object from which 'eval' originated. This
|
|
|
|
// is not mandated by the spec.
|
2011-10-31 09:38:52 +00:00
|
|
|
// We only throw if the global has been detached, since we need the
|
|
|
|
// receiver as this-value for the call.
|
2013-12-11 13:51:48 +00:00
|
|
|
if (!%IsAttachedGlobal(global)) {
|
2011-10-31 09:38:52 +00:00
|
|
|
throw new $EvalError('The "this" value passed to eval must ' +
|
2008-11-14 14:36:46 +00:00
|
|
|
'be the global object from which eval originated');
|
2008-11-14 13:14:49 +00:00
|
|
|
}
|
2009-06-08 09:46:09 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
var global_proxy = %GlobalProxy(global);
|
2013-12-11 13:51:48 +00:00
|
|
|
|
2013-03-07 15:46:14 +00:00
|
|
|
var f = %CompileString(x, false);
|
2008-10-03 18:00:28 +00:00
|
|
|
if (!IS_FUNCTION(f)) return f;
|
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
return %_CallFunction(global_proxy, f);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up global object.
|
|
|
|
function SetUpGlobal() {
|
|
|
|
%CheckIsBootstrapping();
|
2013-04-11 12:15:25 +00:00
|
|
|
|
2013-10-17 10:02:45 +00:00
|
|
|
var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA 262 - 15.1.1.1.
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(global, "NaN", NAN, attributes);
|
2008-10-03 18:00:28 +00:00
|
|
|
|
|
|
|
// ECMA-262 - 15.1.1.2.
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(global, "Infinity", INFINITY, attributes);
|
2008-10-03 18:00:28 +00:00
|
|
|
|
|
|
|
// ECMA-262 - 15.1.1.3.
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(global, "undefined", UNDEFINED, attributes);
|
2009-06-29 08:14:06 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up non-enumerable function on the global object.
|
2008-10-03 18:00:28 +00:00
|
|
|
InstallFunctions(global, DONT_ENUM, $Array(
|
|
|
|
"isNaN", GlobalIsNaN,
|
|
|
|
"isFinite", GlobalIsFinite,
|
|
|
|
"parseInt", GlobalParseInt,
|
|
|
|
"parseFloat", GlobalParseFloat,
|
2011-05-19 08:10:27 +00:00
|
|
|
"eval", GlobalEval
|
2008-10-03 18:00:28 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpGlobal();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Object
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.2
|
|
|
|
function ObjectToString() {
|
2013-03-01 13:28:55 +00:00
|
|
|
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
|
|
|
|
if (IS_NULL(this)) return "[object Null]";
|
2010-01-19 14:15:47 +00:00
|
|
|
return "[object " + %_ClassOf(ToObject(this)) + "]";
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.3
|
|
|
|
function ObjectToLocaleString() {
|
2014-01-31 10:05:58 +00:00
|
|
|
CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString");
|
2008-07-03 15:10:15 +00:00
|
|
|
return this.toString();
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.4
|
|
|
|
function ObjectValueOf() {
|
2010-01-19 14:15:47 +00:00
|
|
|
return ToObject(this);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.5
|
|
|
|
function ObjectHasOwnProperty(V) {
|
2011-07-21 11:20:27 +00:00
|
|
|
if (%IsJSProxy(this)) {
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
|
|
|
if (IS_SYMBOL(V)) return false;
|
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
var handler = %GetHandler(this);
|
2013-03-04 15:00:57 +00:00
|
|
|
return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V));
|
2011-07-21 11:20:27 +00:00
|
|
|
}
|
2014-05-22 15:27:57 +00:00
|
|
|
return %HasOwnProperty(TO_OBJECT_INLINE(this), ToName(V));
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.6
|
|
|
|
function ObjectIsPrototypeOf(V) {
|
2014-01-31 10:05:58 +00:00
|
|
|
CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf");
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(V)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
return %IsInPrototypeChain(this, V);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ECMA-262 - 15.2.4.6
|
|
|
|
function ObjectPropertyIsEnumerable(V) {
|
2013-03-04 15:00:57 +00:00
|
|
|
var P = ToName(V);
|
2011-07-21 11:20:27 +00:00
|
|
|
if (%IsJSProxy(this)) {
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
|
|
|
if (IS_SYMBOL(V)) return false;
|
|
|
|
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(this, P);
|
2011-07-21 11:20:27 +00:00
|
|
|
return IS_UNDEFINED(desc) ? false : desc.isEnumerable();
|
|
|
|
}
|
|
|
|
return %IsPropertyEnumerable(ToObject(this), P);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Extensions for providing property getters and setters.
|
2008-10-03 18:00:28 +00:00
|
|
|
function ObjectDefineGetter(name, fun) {
|
2011-05-30 13:49:22 +00:00
|
|
|
var receiver = this;
|
|
|
|
if (receiver == null && !IS_UNDETECTABLE(receiver)) {
|
2014-07-01 12:12:34 +00:00
|
|
|
receiver = %GlobalProxy(global);
|
2008-10-03 12:14:29 +00:00
|
|
|
}
|
2011-09-13 11:42:57 +00:00
|
|
|
if (!IS_SPEC_FUNCTION(fun)) {
|
2011-11-28 12:11:00 +00:00
|
|
|
throw new $TypeError(
|
|
|
|
'Object.prototype.__defineGetter__: Expecting function');
|
2008-10-03 12:14:29 +00:00
|
|
|
}
|
2011-03-15 12:25:13 +00:00
|
|
|
var desc = new PropertyDescriptor();
|
|
|
|
desc.setGet(fun);
|
|
|
|
desc.setEnumerable(true);
|
|
|
|
desc.setConfigurable(true);
|
2013-03-04 15:00:57 +00:00
|
|
|
DefineOwnProperty(ToObject(receiver), ToName(name), desc, false);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function ObjectLookupGetter(name) {
|
2011-05-30 13:49:22 +00:00
|
|
|
var receiver = this;
|
|
|
|
if (receiver == null && !IS_UNDETECTABLE(receiver)) {
|
2014-07-01 12:12:34 +00:00
|
|
|
receiver = %GlobalProxy(global);
|
2008-10-03 12:14:29 +00:00
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
return %LookupAccessor(ToObject(receiver), ToName(name), GETTER);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function ObjectDefineSetter(name, fun) {
|
2011-05-30 13:49:22 +00:00
|
|
|
var receiver = this;
|
|
|
|
if (receiver == null && !IS_UNDETECTABLE(receiver)) {
|
2014-07-01 12:12:34 +00:00
|
|
|
receiver = %GlobalProxy(global);
|
2008-10-03 12:14:29 +00:00
|
|
|
}
|
2011-09-13 11:42:57 +00:00
|
|
|
if (!IS_SPEC_FUNCTION(fun)) {
|
2008-10-03 12:14:29 +00:00
|
|
|
throw new $TypeError(
|
|
|
|
'Object.prototype.__defineSetter__: Expecting function');
|
|
|
|
}
|
2011-03-15 12:25:13 +00:00
|
|
|
var desc = new PropertyDescriptor();
|
|
|
|
desc.setSet(fun);
|
|
|
|
desc.setEnumerable(true);
|
|
|
|
desc.setConfigurable(true);
|
2013-03-04 15:00:57 +00:00
|
|
|
DefineOwnProperty(ToObject(receiver), ToName(name), desc, false);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function ObjectLookupSetter(name) {
|
2011-05-30 13:49:22 +00:00
|
|
|
var receiver = this;
|
|
|
|
if (receiver == null && !IS_UNDETECTABLE(receiver)) {
|
2014-07-01 12:12:34 +00:00
|
|
|
receiver = %GlobalProxy(global);
|
2008-10-03 12:14:29 +00:00
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
return %LookupAccessor(ToObject(receiver), ToName(name), SETTER);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-09-15 11:51:40 +00:00
|
|
|
function ObjectKeys(obj) {
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.keys"]);
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2011-07-13 11:01:17 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
var handler = %GetHandler(obj);
|
2011-07-21 11:20:27 +00:00
|
|
|
var names = CallTrap0(handler, "keys", DerivedKeysTrap);
|
2013-03-06 13:55:21 +00:00
|
|
|
return ToNameArray(names, "keys", false);
|
2011-07-13 11:01:17 +00:00
|
|
|
}
|
2014-05-22 15:27:57 +00:00
|
|
|
return %OwnKeys(obj);
|
2009-09-15 11:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 13:56:58 +00:00
|
|
|
// ES5 8.10.1.
|
|
|
|
function IsAccessorDescriptor(desc) {
|
|
|
|
if (IS_UNDEFINED(desc)) return false;
|
2011-07-07 12:41:20 +00:00
|
|
|
return desc.hasGetter() || desc.hasSetter();
|
2009-12-09 13:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ES5 8.10.2.
|
|
|
|
function IsDataDescriptor(desc) {
|
|
|
|
if (IS_UNDEFINED(desc)) return false;
|
2011-07-07 12:41:20 +00:00
|
|
|
return desc.hasValue() || desc.hasWritable();
|
2009-12-09 13:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ES5 8.10.3.
|
|
|
|
function IsGenericDescriptor(desc) {
|
2011-10-20 07:55:30 +00:00
|
|
|
if (IS_UNDEFINED(desc)) return false;
|
2009-12-09 13:56:58 +00:00
|
|
|
return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function IsInconsistentDescriptor(desc) {
|
|
|
|
return IsAccessorDescriptor(desc) && IsDataDescriptor(desc);
|
|
|
|
}
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
|
2010-01-13 12:10:57 +00:00
|
|
|
// ES5 8.10.4
|
|
|
|
function FromPropertyDescriptor(desc) {
|
2010-02-03 13:10:03 +00:00
|
|
|
if (IS_UNDEFINED(desc)) return desc;
|
2011-08-25 09:07:43 +00:00
|
|
|
|
2010-01-13 12:10:57 +00:00
|
|
|
if (IsDataDescriptor(desc)) {
|
2011-08-25 09:07:43 +00:00
|
|
|
return { value: desc.getValue(),
|
|
|
|
writable: desc.isWritable(),
|
|
|
|
enumerable: desc.isEnumerable(),
|
|
|
|
configurable: desc.isConfigurable() };
|
2010-01-13 12:10:57 +00:00
|
|
|
}
|
2011-08-25 09:07:43 +00:00
|
|
|
// Must be an AccessorDescriptor then. We never return a generic descriptor.
|
|
|
|
return { get: desc.getGet(),
|
2014-02-06 16:09:45 +00:00
|
|
|
set: desc.getSet(),
|
2011-08-25 09:07:43 +00:00
|
|
|
enumerable: desc.isEnumerable(),
|
|
|
|
configurable: desc.isConfigurable() };
|
2010-01-13 12:10:57 +00:00
|
|
|
}
|
2009-12-09 13:56:58 +00:00
|
|
|
|
2011-08-25 09:07:43 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
// Harmony Proxies
|
|
|
|
function FromGenericPropertyDescriptor(desc) {
|
|
|
|
if (IS_UNDEFINED(desc)) return desc;
|
|
|
|
var obj = new $Object();
|
2011-08-25 09:07:43 +00:00
|
|
|
|
|
|
|
if (desc.hasValue()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "value", desc.getValue(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
|
|
|
if (desc.hasWritable()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "writable", desc.isWritable(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
|
|
|
if (desc.hasGetter()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "get", desc.getGet(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
|
|
|
if (desc.hasSetter()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "set", desc.getSet(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
|
|
|
if (desc.hasEnumerable()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "enumerable", desc.isEnumerable(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
|
|
|
if (desc.hasConfigurable()) {
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty(obj, "configurable", desc.isConfigurable(), NONE);
|
2011-08-25 09:07:43 +00:00
|
|
|
}
|
2011-07-07 12:41:20 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-08-25 09:07:43 +00:00
|
|
|
|
2009-12-09 13:56:58 +00:00
|
|
|
// ES5 8.10.5.
|
|
|
|
function ToPropertyDescriptor(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2009-12-09 13:56:58 +00:00
|
|
|
throw MakeTypeError("property_desc_object", [obj]);
|
|
|
|
}
|
|
|
|
var desc = new PropertyDescriptor();
|
|
|
|
|
|
|
|
if ("enumerable" in obj) {
|
|
|
|
desc.setEnumerable(ToBoolean(obj.enumerable));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("configurable" in obj) {
|
|
|
|
desc.setConfigurable(ToBoolean(obj.configurable));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("value" in obj) {
|
|
|
|
desc.setValue(obj.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("writable" in obj) {
|
|
|
|
desc.setWritable(ToBoolean(obj.writable));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("get" in obj) {
|
|
|
|
var get = obj.get;
|
2011-09-13 11:42:57 +00:00
|
|
|
if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) {
|
2009-12-09 13:56:58 +00:00
|
|
|
throw MakeTypeError("getter_must_be_callable", [get]);
|
|
|
|
}
|
|
|
|
desc.setGet(get);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("set" in obj) {
|
|
|
|
var set = obj.set;
|
2011-09-13 11:42:57 +00:00
|
|
|
if (!IS_UNDEFINED(set) && !IS_SPEC_FUNCTION(set)) {
|
2009-12-09 13:56:58 +00:00
|
|
|
throw MakeTypeError("setter_must_be_callable", [set]);
|
|
|
|
}
|
|
|
|
desc.setSet(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsInconsistentDescriptor(desc)) {
|
|
|
|
throw MakeTypeError("value_and_accessor", [obj]);
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
// For Harmony proxies.
|
|
|
|
function ToCompletePropertyDescriptor(obj) {
|
2011-11-28 12:11:00 +00:00
|
|
|
var desc = ToPropertyDescriptor(obj);
|
2011-06-03 10:15:49 +00:00
|
|
|
if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) {
|
2013-10-17 10:02:45 +00:00
|
|
|
if (!desc.hasValue()) desc.setValue(UNDEFINED);
|
2011-07-07 12:41:20 +00:00
|
|
|
if (!desc.hasWritable()) desc.setWritable(false);
|
2011-06-03 10:15:49 +00:00
|
|
|
} else {
|
|
|
|
// Is accessor descriptor.
|
2013-10-17 10:02:45 +00:00
|
|
|
if (!desc.hasGetter()) desc.setGet(UNDEFINED);
|
|
|
|
if (!desc.hasSetter()) desc.setSet(UNDEFINED);
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
2011-07-07 12:41:20 +00:00
|
|
|
if (!desc.hasEnumerable()) desc.setEnumerable(false);
|
|
|
|
if (!desc.hasConfigurable()) desc.setConfigurable(false);
|
2011-06-03 10:15:49 +00:00
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 13:56:58 +00:00
|
|
|
function PropertyDescriptor() {
|
|
|
|
// Initialize here so they are all in-object and have the same map.
|
|
|
|
// Default values from ES5 8.6.1.
|
2013-10-17 10:02:45 +00:00
|
|
|
this.value_ = UNDEFINED;
|
2009-12-09 13:56:58 +00:00
|
|
|
this.hasValue_ = false;
|
|
|
|
this.writable_ = false;
|
|
|
|
this.hasWritable_ = false;
|
|
|
|
this.enumerable_ = false;
|
2010-02-03 13:10:03 +00:00
|
|
|
this.hasEnumerable_ = false;
|
2009-12-09 13:56:58 +00:00
|
|
|
this.configurable_ = false;
|
2010-02-03 13:10:03 +00:00
|
|
|
this.hasConfigurable_ = false;
|
2013-10-17 10:02:45 +00:00
|
|
|
this.get_ = UNDEFINED;
|
2009-12-09 13:56:58 +00:00
|
|
|
this.hasGetter_ = false;
|
2013-10-17 10:02:45 +00:00
|
|
|
this.set_ = UNDEFINED;
|
2009-12-09 13:56:58 +00:00
|
|
|
this.hasSetter_ = false;
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpLockedPrototype(PropertyDescriptor, $Array(
|
|
|
|
"value_",
|
|
|
|
"hasValue_",
|
|
|
|
"writable_",
|
|
|
|
"hasWritable_",
|
|
|
|
"enumerable_",
|
|
|
|
"hasEnumerable_",
|
|
|
|
"configurable_",
|
|
|
|
"hasConfigurable_",
|
|
|
|
"get_",
|
|
|
|
"hasGetter_",
|
|
|
|
"set_",
|
|
|
|
"hasSetter_"
|
|
|
|
), $Array(
|
|
|
|
"toString", function() {
|
|
|
|
return "[object PropertyDescriptor]";
|
|
|
|
},
|
|
|
|
"setValue", function(value) {
|
|
|
|
this.value_ = value;
|
|
|
|
this.hasValue_ = true;
|
|
|
|
},
|
|
|
|
"getValue", function() {
|
|
|
|
return this.value_;
|
|
|
|
},
|
|
|
|
"hasValue", function() {
|
|
|
|
return this.hasValue_;
|
|
|
|
},
|
|
|
|
"setEnumerable", function(enumerable) {
|
|
|
|
this.enumerable_ = enumerable;
|
|
|
|
this.hasEnumerable_ = true;
|
|
|
|
},
|
|
|
|
"isEnumerable", function () {
|
|
|
|
return this.enumerable_;
|
|
|
|
},
|
|
|
|
"hasEnumerable", function() {
|
|
|
|
return this.hasEnumerable_;
|
|
|
|
},
|
|
|
|
"setWritable", function(writable) {
|
|
|
|
this.writable_ = writable;
|
|
|
|
this.hasWritable_ = true;
|
|
|
|
},
|
|
|
|
"isWritable", function() {
|
|
|
|
return this.writable_;
|
|
|
|
},
|
|
|
|
"hasWritable", function() {
|
|
|
|
return this.hasWritable_;
|
|
|
|
},
|
|
|
|
"setConfigurable", function(configurable) {
|
|
|
|
this.configurable_ = configurable;
|
|
|
|
this.hasConfigurable_ = true;
|
|
|
|
},
|
|
|
|
"hasConfigurable", function() {
|
|
|
|
return this.hasConfigurable_;
|
|
|
|
},
|
|
|
|
"isConfigurable", function() {
|
|
|
|
return this.configurable_;
|
|
|
|
},
|
|
|
|
"setGet", function(get) {
|
|
|
|
this.get_ = get;
|
|
|
|
this.hasGetter_ = true;
|
|
|
|
},
|
|
|
|
"getGet", function() {
|
|
|
|
return this.get_;
|
|
|
|
},
|
|
|
|
"hasGetter", function() {
|
|
|
|
return this.hasGetter_;
|
|
|
|
},
|
|
|
|
"setSet", function(set) {
|
|
|
|
this.set_ = set;
|
|
|
|
this.hasSetter_ = true;
|
|
|
|
},
|
|
|
|
"getSet", function() {
|
|
|
|
return this.set_;
|
|
|
|
},
|
|
|
|
"hasSetter", function() {
|
|
|
|
return this.hasSetter_;
|
|
|
|
}));
|
2010-02-03 13:10:03 +00:00
|
|
|
|
|
|
|
|
2011-02-04 12:14:56 +00:00
|
|
|
// Converts an array returned from Runtime_GetOwnProperty to an actual
|
|
|
|
// property descriptor. For a description of the array layout please
|
|
|
|
// see the runtime.cc file.
|
|
|
|
function ConvertDescriptorArrayToDescriptor(desc_array) {
|
|
|
|
if (IS_UNDEFINED(desc_array)) {
|
2013-10-17 10:02:45 +00:00
|
|
|
return UNDEFINED;
|
2011-02-04 12:14:56 +00:00
|
|
|
}
|
2010-01-13 12:10:57 +00:00
|
|
|
|
2011-02-04 12:14:56 +00:00
|
|
|
var desc = new PropertyDescriptor();
|
|
|
|
// This is an accessor.
|
|
|
|
if (desc_array[IS_ACCESSOR_INDEX]) {
|
|
|
|
desc.setGet(desc_array[GETTER_INDEX]);
|
|
|
|
desc.setSet(desc_array[SETTER_INDEX]);
|
2010-01-13 12:10:57 +00:00
|
|
|
} else {
|
2011-02-04 12:14:56 +00:00
|
|
|
desc.setValue(desc_array[VALUE_INDEX]);
|
|
|
|
desc.setWritable(desc_array[WRITABLE_INDEX]);
|
2010-01-13 12:10:57 +00:00
|
|
|
}
|
2011-02-04 12:14:56 +00:00
|
|
|
desc.setEnumerable(desc_array[ENUMERABLE_INDEX]);
|
|
|
|
desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]);
|
2010-01-13 12:10:57 +00:00
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
// For Harmony proxies.
|
|
|
|
function GetTrap(handler, name, defaultTrap) {
|
|
|
|
var trap = handler[name];
|
|
|
|
if (IS_UNDEFINED(trap)) {
|
|
|
|
if (IS_UNDEFINED(defaultTrap)) {
|
|
|
|
throw MakeTypeError("handler_trap_missing", [handler, name]);
|
|
|
|
}
|
|
|
|
trap = defaultTrap;
|
2011-09-13 11:42:57 +00:00
|
|
|
} else if (!IS_SPEC_FUNCTION(trap)) {
|
2011-07-21 11:20:27 +00:00
|
|
|
throw MakeTypeError("handler_trap_must_be_callable", [handler, name]);
|
|
|
|
}
|
|
|
|
return trap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function CallTrap0(handler, name, defaultTrap) {
|
|
|
|
return %_CallFunction(handler, GetTrap(handler, name, defaultTrap));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function CallTrap1(handler, name, defaultTrap, x) {
|
|
|
|
return %_CallFunction(handler, x, GetTrap(handler, name, defaultTrap));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function CallTrap2(handler, name, defaultTrap, x, y) {
|
|
|
|
return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-04 12:14:56 +00:00
|
|
|
// ES5 section 8.12.1.
|
2014-05-14 08:51:10 +00:00
|
|
|
function GetOwnPropertyJS(obj, v) {
|
2013-03-04 15:00:57 +00:00
|
|
|
var p = ToName(v);
|
2011-07-13 11:57:15 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
2013-10-17 10:02:45 +00:00
|
|
|
if (IS_SYMBOL(v)) return UNDEFINED;
|
2013-03-22 17:27:44 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
var handler = %GetHandler(obj);
|
2013-10-17 10:02:45 +00:00
|
|
|
var descriptor = CallTrap1(
|
|
|
|
handler, "getOwnPropertyDescriptor", UNDEFINED, p);
|
2011-07-13 11:57:15 +00:00
|
|
|
if (IS_UNDEFINED(descriptor)) return descriptor;
|
|
|
|
var desc = ToCompletePropertyDescriptor(descriptor);
|
|
|
|
if (!desc.isConfigurable()) {
|
|
|
|
throw MakeTypeError("proxy_prop_not_configurable",
|
|
|
|
[handler, "getOwnPropertyDescriptor", p, descriptor]);
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2011-02-04 12:14:56 +00:00
|
|
|
// GetOwnProperty returns an array indexed by the constants
|
|
|
|
// defined in macros.py.
|
|
|
|
// If p is not a property on obj undefined is returned.
|
2013-03-04 15:00:57 +00:00
|
|
|
var props = %GetOwnProperty(ToObject(obj), p);
|
2011-02-04 12:14:56 +00:00
|
|
|
|
|
|
|
return ConvertDescriptorArrayToDescriptor(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-05 09:53:43 +00:00
|
|
|
// ES5 section 8.12.7.
|
|
|
|
function Delete(obj, p, should_throw) {
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, p);
|
2011-12-05 09:53:43 +00:00
|
|
|
if (IS_UNDEFINED(desc)) return true;
|
|
|
|
if (desc.isConfigurable()) {
|
|
|
|
%DeleteProperty(obj, p, 0);
|
|
|
|
return true;
|
|
|
|
} else if (should_throw) {
|
|
|
|
throw MakeTypeError("define_disallowed", [p]);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
// Harmony proxies.
|
|
|
|
function DefineProxyProperty(obj, p, attributes, should_throw) {
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
|
|
|
if (IS_SYMBOL(p)) return false;
|
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
var handler = %GetHandler(obj);
|
2013-10-17 10:02:45 +00:00
|
|
|
var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
|
2011-07-07 12:41:20 +00:00
|
|
|
if (!ToBoolean(result)) {
|
|
|
|
if (should_throw) {
|
2011-07-18 13:04:52 +00:00
|
|
|
throw MakeTypeError("handler_returned_false",
|
|
|
|
[handler, "defineProperty"]);
|
2011-07-07 12:41:20 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 07:15:23 +00:00
|
|
|
// ES5 8.12.9.
|
2011-12-05 09:53:43 +00:00
|
|
|
function DefineObjectProperty(obj, p, desc, should_throw) {
|
2014-08-27 11:42:17 +00:00
|
|
|
var current_array = %GetOwnProperty(ToObject(obj), ToName(p));
|
|
|
|
var current = ConvertDescriptorArrayToDescriptor(current_array);
|
2010-02-03 13:10:03 +00:00
|
|
|
var extensible = %IsExtensible(ToObject(obj));
|
|
|
|
|
|
|
|
// Error handling according to spec.
|
|
|
|
// Step 3
|
2011-03-15 14:19:18 +00:00
|
|
|
if (IS_UNDEFINED(current) && !extensible) {
|
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("define_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-03 13:10:03 +00:00
|
|
|
|
2011-02-03 19:29:10 +00:00
|
|
|
if (!IS_UNDEFINED(current)) {
|
2010-07-23 10:08:55 +00:00
|
|
|
// Step 5 and 6
|
2011-02-03 19:29:10 +00:00
|
|
|
if ((IsGenericDescriptor(desc) ||
|
|
|
|
IsDataDescriptor(desc) == IsDataDescriptor(current)) &&
|
|
|
|
(!desc.hasEnumerable() ||
|
|
|
|
SameValue(desc.isEnumerable(), current.isEnumerable())) &&
|
2010-10-15 13:03:59 +00:00
|
|
|
(!desc.hasConfigurable() ||
|
2010-07-23 10:08:55 +00:00
|
|
|
SameValue(desc.isConfigurable(), current.isConfigurable())) &&
|
2010-10-15 13:03:59 +00:00
|
|
|
(!desc.hasWritable() ||
|
2010-07-23 10:08:55 +00:00
|
|
|
SameValue(desc.isWritable(), current.isWritable())) &&
|
|
|
|
(!desc.hasValue() ||
|
|
|
|
SameValue(desc.getValue(), current.getValue())) &&
|
|
|
|
(!desc.hasGetter() ||
|
|
|
|
SameValue(desc.getGet(), current.getGet())) &&
|
|
|
|
(!desc.hasSetter() ||
|
|
|
|
SameValue(desc.getSet(), current.getSet()))) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
if (!current.isConfigurable()) {
|
|
|
|
// Step 7
|
|
|
|
if (desc.isConfigurable() ||
|
|
|
|
(desc.hasEnumerable() &&
|
2011-02-14 10:43:21 +00:00
|
|
|
desc.isEnumerable() != current.isEnumerable())) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-14 10:43:21 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
// Step 8
|
|
|
|
if (!IsGenericDescriptor(desc)) {
|
|
|
|
// Step 9a
|
2011-02-14 10:43:21 +00:00
|
|
|
if (IsDataDescriptor(current) != IsDataDescriptor(desc)) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-14 10:43:21 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
// Step 10a
|
|
|
|
if (IsDataDescriptor(current) && IsDataDescriptor(desc)) {
|
2011-02-14 10:43:21 +00:00
|
|
|
if (!current.isWritable() && desc.isWritable()) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-14 10:43:21 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
if (!current.isWritable() && desc.hasValue() &&
|
|
|
|
!SameValue(desc.getValue(), current.getValue())) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Step 11
|
|
|
|
if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) {
|
2011-02-14 10:43:21 +00:00
|
|
|
if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
}
|
2011-02-14 10:43:21 +00:00
|
|
|
if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) {
|
2011-03-15 14:19:18 +00:00
|
|
|
if (should_throw) {
|
2011-06-16 06:37:49 +00:00
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
2011-03-15 14:19:18 +00:00
|
|
|
} else {
|
2011-10-19 13:29:37 +00:00
|
|
|
return false;
|
2011-03-15 14:19:18 +00:00
|
|
|
}
|
2011-02-14 10:43:21 +00:00
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
}
|
2010-02-03 13:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-30 07:15:23 +00:00
|
|
|
// Send flags - enumerable and configurable are common - writable is
|
2010-02-03 13:10:03 +00:00
|
|
|
// only send to the data descriptor.
|
|
|
|
// Take special care if enumerable and configurable is not defined on
|
|
|
|
// desc (we need to preserve the existing values from current).
|
|
|
|
var flag = NONE;
|
|
|
|
if (desc.hasEnumerable()) {
|
|
|
|
flag |= desc.isEnumerable() ? 0 : DONT_ENUM;
|
|
|
|
} else if (!IS_UNDEFINED(current)) {
|
|
|
|
flag |= current.isEnumerable() ? 0 : DONT_ENUM;
|
2009-12-09 13:56:58 +00:00
|
|
|
} else {
|
2010-02-03 13:10:03 +00:00
|
|
|
flag |= DONT_ENUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.hasConfigurable()) {
|
|
|
|
flag |= desc.isConfigurable() ? 0 : DONT_DELETE;
|
|
|
|
} else if (!IS_UNDEFINED(current)) {
|
|
|
|
flag |= current.isConfigurable() ? 0 : DONT_DELETE;
|
|
|
|
} else
|
|
|
|
flag |= DONT_DELETE;
|
|
|
|
|
2011-02-03 19:29:10 +00:00
|
|
|
if (IsDataDescriptor(desc) ||
|
|
|
|
(IsGenericDescriptor(desc) &&
|
|
|
|
(IS_UNDEFINED(current) || IsDataDescriptor(current)))) {
|
|
|
|
// There are 3 cases that lead here:
|
|
|
|
// Step 4a - defining a new data property.
|
|
|
|
// Steps 9b & 12 - replacing an existing accessor property with a data
|
|
|
|
// property.
|
|
|
|
// Step 12 - updating an existing data property with a data or generic
|
|
|
|
// descriptor.
|
|
|
|
|
2010-05-26 08:31:57 +00:00
|
|
|
if (desc.hasWritable()) {
|
|
|
|
flag |= desc.isWritable() ? 0 : READ_ONLY;
|
|
|
|
} else if (!IS_UNDEFINED(current)) {
|
|
|
|
flag |= current.isWritable() ? 0 : READ_ONLY;
|
|
|
|
} else {
|
|
|
|
flag |= READ_ONLY;
|
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
|
2013-10-17 10:02:45 +00:00
|
|
|
var value = UNDEFINED; // Default value is undefined.
|
2010-12-10 11:27:15 +00:00
|
|
|
if (desc.hasValue()) {
|
|
|
|
value = desc.getValue();
|
2011-02-03 19:29:10 +00:00
|
|
|
} else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) {
|
2010-12-10 11:27:15 +00:00
|
|
|
value = current.getValue();
|
|
|
|
}
|
2011-02-03 19:29:10 +00:00
|
|
|
|
2014-06-27 13:48:37 +00:00
|
|
|
%DefineDataPropertyUnchecked(obj, p, value, flag);
|
2010-02-03 13:10:03 +00:00
|
|
|
} else {
|
2011-02-03 19:29:10 +00:00
|
|
|
// There are 3 cases that lead here:
|
|
|
|
// Step 4b - defining a new accessor property.
|
|
|
|
// Steps 9c & 12 - replacing an existing data property with an accessor
|
|
|
|
// property.
|
|
|
|
// Step 12 - updating an existing accessor property with an accessor
|
|
|
|
// descriptor.
|
2014-08-19 17:02:04 +00:00
|
|
|
var getter = null;
|
|
|
|
if (desc.hasGetter()) {
|
|
|
|
getter = desc.getGet();
|
|
|
|
} else if (IsAccessorDescriptor(current) && current.hasGetter()) {
|
|
|
|
getter = current.getGet();
|
|
|
|
}
|
|
|
|
var setter = null;
|
|
|
|
if (desc.hasSetter()) {
|
|
|
|
setter = desc.getSet();
|
|
|
|
} else if (IsAccessorDescriptor(current) && current.hasSetter()) {
|
|
|
|
setter = current.getSet();
|
|
|
|
}
|
2014-06-27 13:48:37 +00:00
|
|
|
%DefineAccessorPropertyUnchecked(obj, p, getter, setter, flag);
|
2009-12-09 13:56:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-05 09:53:43 +00:00
|
|
|
// ES5 section 15.4.5.1.
|
|
|
|
function DefineArrayProperty(obj, p, desc, should_throw) {
|
|
|
|
// Note that the length of an array is not actually stored as part of the
|
|
|
|
// property, hence we use generated code throughout this function instead of
|
|
|
|
// DefineObjectProperty() to modify its value.
|
|
|
|
|
|
|
|
// Step 3 - Special handling for length property.
|
2013-03-22 16:33:50 +00:00
|
|
|
if (p === "length") {
|
2011-12-05 09:53:43 +00:00
|
|
|
var length = obj.length;
|
2013-06-04 23:58:49 +00:00
|
|
|
var old_length = length;
|
2011-12-05 09:53:43 +00:00
|
|
|
if (!desc.hasValue()) {
|
|
|
|
return DefineObjectProperty(obj, "length", desc, should_throw);
|
|
|
|
}
|
|
|
|
var new_length = ToUint32(desc.getValue());
|
|
|
|
if (new_length != ToNumber(desc.getValue())) {
|
|
|
|
throw new $RangeError('defineProperty() array length out of range');
|
|
|
|
}
|
2014-05-14 08:51:10 +00:00
|
|
|
var length_desc = GetOwnPropertyJS(obj, "length");
|
2011-12-12 10:20:46 +00:00
|
|
|
if (new_length != length && !length_desc.isWritable()) {
|
|
|
|
if (should_throw) {
|
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var threw = false;
|
2013-06-04 23:58:49 +00:00
|
|
|
|
|
|
|
var emit_splice = %IsObserved(obj) && new_length !== old_length;
|
|
|
|
var removed;
|
|
|
|
if (emit_splice) {
|
|
|
|
BeginPerformSplice(obj);
|
|
|
|
removed = [];
|
|
|
|
if (new_length < old_length)
|
|
|
|
removed.length = old_length - new_length;
|
|
|
|
}
|
|
|
|
|
2011-12-12 10:20:46 +00:00
|
|
|
while (new_length < length--) {
|
2013-06-04 23:58:49 +00:00
|
|
|
var index = ToString(length);
|
|
|
|
if (emit_splice) {
|
2014-05-14 08:51:10 +00:00
|
|
|
var deletedDesc = GetOwnPropertyJS(obj, index);
|
2013-06-04 23:58:49 +00:00
|
|
|
if (deletedDesc && deletedDesc.hasValue())
|
|
|
|
removed[length - new_length] = deletedDesc.getValue();
|
|
|
|
}
|
|
|
|
if (!Delete(obj, index, false)) {
|
2011-12-12 10:20:46 +00:00
|
|
|
new_length = length + 1;
|
|
|
|
threw = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 09:53:43 +00:00
|
|
|
// Make sure the below call to DefineObjectProperty() doesn't overwrite
|
|
|
|
// any magic "length" property by removing the value.
|
2012-12-13 09:31:44 +00:00
|
|
|
// TODO(mstarzinger): This hack should be removed once we have addressed the
|
2014-06-27 13:48:37 +00:00
|
|
|
// respective TODO in Runtime_DefineDataPropertyUnchecked.
|
2012-12-13 09:31:44 +00:00
|
|
|
// For the time being, we need a hack to prevent Object.observe from
|
|
|
|
// generating two change records.
|
2011-12-12 10:20:46 +00:00
|
|
|
obj.length = new_length;
|
2013-10-17 10:02:45 +00:00
|
|
|
desc.value_ = UNDEFINED;
|
2011-12-05 09:53:43 +00:00
|
|
|
desc.hasValue_ = false;
|
2012-12-13 09:31:44 +00:00
|
|
|
threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
|
2013-06-04 23:58:49 +00:00
|
|
|
if (emit_splice) {
|
|
|
|
EndPerformSplice(obj);
|
|
|
|
EnqueueSpliceRecord(obj,
|
|
|
|
new_length < old_length ? new_length : old_length,
|
|
|
|
removed,
|
|
|
|
new_length > old_length ? new_length - old_length : 0);
|
|
|
|
}
|
2012-12-13 09:31:44 +00:00
|
|
|
if (threw) {
|
2011-12-05 09:53:43 +00:00
|
|
|
if (should_throw) {
|
|
|
|
throw MakeTypeError("redefine_disallowed", [p]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 4 - Special handling for array index.
|
2014-08-11 19:24:05 +00:00
|
|
|
if (!IS_SYMBOL(p)) {
|
|
|
|
var index = ToUint32(p);
|
|
|
|
var emit_splice = false;
|
|
|
|
if (ToString(index) == p && index != 4294967295) {
|
|
|
|
var length = obj.length;
|
|
|
|
if (index >= length && %IsObserved(obj)) {
|
|
|
|
emit_splice = true;
|
|
|
|
BeginPerformSplice(obj);
|
|
|
|
}
|
2013-06-04 23:58:49 +00:00
|
|
|
|
2014-08-11 19:24:05 +00:00
|
|
|
var length_desc = GetOwnPropertyJS(obj, "length");
|
|
|
|
if ((index >= length && !length_desc.isWritable()) ||
|
|
|
|
!DefineObjectProperty(obj, p, desc, true)) {
|
|
|
|
if (emit_splice)
|
|
|
|
EndPerformSplice(obj);
|
|
|
|
if (should_throw) {
|
|
|
|
throw MakeTypeError("define_disallowed", [p]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index >= length) {
|
|
|
|
obj.length = index + 1;
|
|
|
|
}
|
|
|
|
if (emit_splice) {
|
2013-06-04 23:58:49 +00:00
|
|
|
EndPerformSplice(obj);
|
2014-08-11 19:24:05 +00:00
|
|
|
EnqueueSpliceRecord(obj, length, [], index + 1 - length);
|
2011-12-05 09:53:43 +00:00
|
|
|
}
|
2014-08-11 19:24:05 +00:00
|
|
|
return true;
|
2011-12-05 09:53:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 5 - Fallback to default implementation.
|
|
|
|
return DefineObjectProperty(obj, p, desc, should_throw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies.
|
|
|
|
function DefineOwnProperty(obj, p, desc, should_throw) {
|
|
|
|
if (%IsJSProxy(obj)) {
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
|
|
|
if (IS_SYMBOL(p)) return false;
|
|
|
|
|
2011-12-05 09:53:43 +00:00
|
|
|
var attributes = FromGenericPropertyDescriptor(desc);
|
|
|
|
return DefineProxyProperty(obj, p, attributes, should_throw);
|
|
|
|
} else if (IS_ARRAY(obj)) {
|
|
|
|
return DefineArrayProperty(obj, p, desc, should_throw);
|
|
|
|
} else {
|
|
|
|
return DefineObjectProperty(obj, p, desc, should_throw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-07 10:01:24 +00:00
|
|
|
// ES5 section 15.2.3.2.
|
|
|
|
function ObjectGetPrototypeOf(obj) {
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]);
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2011-06-03 10:15:49 +00:00
|
|
|
return %GetPrototype(obj);
|
2010-01-07 10:01:24 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 12:15:57 +00:00
|
|
|
// ES6 section 19.1.2.19.
|
|
|
|
function ObjectSetPrototypeOf(obj, proto) {
|
|
|
|
CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf");
|
|
|
|
|
|
|
|
if (proto !== null && !IS_SPEC_OBJECT(proto)) {
|
|
|
|
throw MakeTypeError("proto_object_or_null", [proto]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_SPEC_OBJECT(obj)) {
|
|
|
|
%SetPrototype(obj, proto);
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-01-07 10:01:24 +00:00
|
|
|
|
2010-03-30 07:15:23 +00:00
|
|
|
// ES5 section 15.2.3.3
|
2010-01-13 12:10:57 +00:00
|
|
|
function ObjectGetOwnPropertyDescriptor(obj, p) {
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object",
|
|
|
|
["Object.getOwnPropertyDescriptor"]);
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, p);
|
2010-01-13 12:10:57 +00:00
|
|
|
return FromPropertyDescriptor(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
// For Harmony proxies
|
2013-03-06 13:55:21 +00:00
|
|
|
function ToNameArray(obj, trap, includeSymbols) {
|
2011-06-03 10:15:49 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
|
|
|
throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]);
|
|
|
|
}
|
|
|
|
var n = ToUint32(obj.length);
|
|
|
|
var array = new $Array(n);
|
2013-03-22 17:27:44 +00:00
|
|
|
var realLength = 0;
|
2012-11-16 09:32:39 +00:00
|
|
|
var names = { __proto__: null }; // TODO(rossberg): use sets once ready.
|
2011-06-03 10:15:49 +00:00
|
|
|
for (var index = 0; index < n; index++) {
|
2013-03-04 15:00:57 +00:00
|
|
|
var s = ToName(obj[index]);
|
2013-03-22 17:27:44 +00:00
|
|
|
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
|
2013-03-06 13:55:21 +00:00
|
|
|
if (IS_SYMBOL(s) && !includeSymbols) continue;
|
2014-05-22 15:27:57 +00:00
|
|
|
if (%HasOwnProperty(names, s)) {
|
2011-11-28 12:11:00 +00:00
|
|
|
throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]);
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
array[index] = s;
|
2013-03-22 17:27:44 +00:00
|
|
|
++realLength;
|
2011-10-24 15:56:18 +00:00
|
|
|
names[s] = 0;
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
2013-03-22 17:27:44 +00:00
|
|
|
array.length = realLength;
|
2011-06-03 10:15:49 +00:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 15:57:30 +00:00
|
|
|
function ObjectGetOwnPropertyKeys(obj, symbolsOnly) {
|
2013-03-12 20:15:03 +00:00
|
|
|
var nameArrays = new InternalArray();
|
2014-01-09 15:57:30 +00:00
|
|
|
var filter = symbolsOnly ?
|
|
|
|
PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL :
|
|
|
|
PROPERTY_ATTRIBUTES_SYMBOLIC;
|
2013-03-12 20:15:03 +00:00
|
|
|
|
2010-01-15 15:34:32 +00:00
|
|
|
// Find all the indexed properties.
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Only get own element names if we want to include string keys.
|
2014-01-09 15:57:30 +00:00
|
|
|
if (!symbolsOnly) {
|
2014-05-22 15:27:57 +00:00
|
|
|
var ownElementNames = %GetOwnElementNames(obj);
|
|
|
|
for (var i = 0; i < ownElementNames.length; ++i) {
|
|
|
|
ownElementNames[i] = %_NumberToString(ownElementNames[i]);
|
2014-01-09 15:57:30 +00:00
|
|
|
}
|
2014-05-22 15:27:57 +00:00
|
|
|
nameArrays.push(ownElementNames);
|
2014-01-09 15:57:30 +00:00
|
|
|
|
|
|
|
// Get names for indexed interceptor properties.
|
|
|
|
var interceptorInfo = %GetInterceptorInfo(obj);
|
|
|
|
if ((interceptorInfo & 1) != 0) {
|
|
|
|
var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
|
|
|
|
if (!IS_UNDEFINED(indexedInterceptorNames)) {
|
|
|
|
nameArrays.push(indexedInterceptorNames);
|
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2010-01-15 15:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find all the named properties.
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Get own property names.
|
|
|
|
nameArrays.push(%GetOwnPropertyNames(obj, filter));
|
2010-01-15 15:34:32 +00:00
|
|
|
|
|
|
|
// Get names for named interceptor properties if any.
|
2013-02-25 18:58:47 +00:00
|
|
|
if ((interceptorInfo & 2) != 0) {
|
2014-01-09 15:57:30 +00:00
|
|
|
var namedInterceptorNames =
|
|
|
|
%GetNamedInterceptorPropertyNames(obj);
|
2013-03-12 20:15:03 +00:00
|
|
|
if (!IS_UNDEFINED(namedInterceptorNames)) {
|
|
|
|
nameArrays.push(namedInterceptorNames);
|
2010-01-15 15:34:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:15:03 +00:00
|
|
|
var propertyNames =
|
|
|
|
%Apply(InternalArray.prototype.concat,
|
|
|
|
nameArrays[0], nameArrays, 1, nameArrays.length - 1);
|
|
|
|
|
|
|
|
// Property names are expected to be unique strings,
|
2013-02-25 18:58:47 +00:00
|
|
|
// but interceptors can interfere with that assumption.
|
|
|
|
if (interceptorInfo != 0) {
|
2014-01-09 15:57:30 +00:00
|
|
|
var seenKeys = { __proto__: null };
|
2013-02-25 18:58:47 +00:00
|
|
|
var j = 0;
|
|
|
|
for (var i = 0; i < propertyNames.length; ++i) {
|
2014-01-09 15:57:30 +00:00
|
|
|
var name = propertyNames[i];
|
|
|
|
if (symbolsOnly) {
|
|
|
|
if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue;
|
|
|
|
} else {
|
|
|
|
if (IS_SYMBOL(name)) continue;
|
|
|
|
name = ToString(name);
|
2013-02-25 18:58:47 +00:00
|
|
|
}
|
2014-01-09 15:57:30 +00:00
|
|
|
if (seenKeys[name]) continue;
|
|
|
|
seenKeys[name] = true;
|
2013-02-25 18:58:47 +00:00
|
|
|
propertyNames[j++] = name;
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2013-02-25 18:58:47 +00:00
|
|
|
propertyNames.length = j;
|
2010-06-28 08:31:31 +00:00
|
|
|
}
|
2010-02-16 10:08:39 +00:00
|
|
|
|
2010-01-15 15:34:32 +00:00
|
|
|
return propertyNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 15:57:30 +00:00
|
|
|
// ES5 section 15.2.3.4.
|
|
|
|
function ObjectGetOwnPropertyNames(obj) {
|
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
|
|
|
|
}
|
|
|
|
// Special handling for proxies.
|
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
var handler = %GetHandler(obj);
|
|
|
|
var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
|
|
|
|
return ToNameArray(names, "getOwnPropertyNames", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ObjectGetOwnPropertyKeys(obj, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 13:56:58 +00:00
|
|
|
// ES5 section 15.2.3.5.
|
|
|
|
function ObjectCreate(proto, properties) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(proto) && proto !== null) {
|
2009-12-09 13:56:58 +00:00
|
|
|
throw MakeTypeError("proto_object_or_null", [proto]);
|
|
|
|
}
|
2014-08-11 14:00:58 +00:00
|
|
|
var obj = {};
|
|
|
|
%InternalSetPrototype(obj, proto);
|
2009-12-09 13:56:58 +00:00
|
|
|
if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-03 13:10:03 +00:00
|
|
|
// ES5 section 15.2.3.6.
|
|
|
|
function ObjectDefineProperty(obj, p, attributes) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]);
|
2010-05-25 06:25:27 +00:00
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
var name = ToName(p);
|
2011-07-07 12:41:20 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
// Clone the attributes object for protection.
|
|
|
|
// TODO(rossberg): not spec'ed yet, so not sure if this should involve
|
|
|
|
// non-own properties as it does (or non-enumerable ones, as it doesn't?).
|
2012-11-16 09:32:39 +00:00
|
|
|
var attributesClone = { __proto__: null };
|
2011-07-07 12:41:20 +00:00
|
|
|
for (var a in attributes) {
|
|
|
|
attributesClone[a] = attributes[a];
|
|
|
|
}
|
|
|
|
DefineProxyProperty(obj, name, attributesClone, true);
|
|
|
|
// The following would implement the spec as in the current proposal,
|
|
|
|
// but after recent comments on es-discuss, is most likely obsolete.
|
|
|
|
/*
|
|
|
|
var defineObj = FromGenericPropertyDescriptor(desc);
|
|
|
|
var names = ObjectGetOwnPropertyNames(attributes);
|
|
|
|
var standardNames =
|
|
|
|
{value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0};
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var N = names[i];
|
2014-05-22 15:27:57 +00:00
|
|
|
if (!(%HasOwnProperty(standardNames, N))) {
|
2014-05-14 08:51:10 +00:00
|
|
|
var attr = GetOwnPropertyJS(attributes, N);
|
2011-07-07 12:41:20 +00:00
|
|
|
DefineOwnProperty(descObj, N, attr, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This is really confusing the types, but it is what the proxies spec
|
|
|
|
// currently requires:
|
|
|
|
desc = descObj;
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
var desc = ToPropertyDescriptor(attributes);
|
|
|
|
DefineOwnProperty(obj, name, desc, true);
|
|
|
|
}
|
2010-02-03 13:10:03 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-14 14:00:33 +00:00
|
|
|
function GetOwnEnumerablePropertyNames(object) {
|
2013-02-15 16:21:03 +00:00
|
|
|
var names = new InternalArray();
|
2014-07-14 14:00:33 +00:00
|
|
|
for (var key in object) {
|
|
|
|
if (%HasOwnProperty(object, key)) {
|
2011-08-18 08:39:06 +00:00
|
|
|
names.push(key);
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 14:00:33 +00:00
|
|
|
|
|
|
|
var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
|
|
|
|
var symbols = %GetOwnPropertyNames(object, filter);
|
|
|
|
for (var i = 0; i < symbols.length; ++i) {
|
|
|
|
var symbol = symbols[i];
|
|
|
|
if (IS_SYMBOL(symbol)) {
|
|
|
|
var desc = ObjectGetOwnPropertyDescriptor(object, symbol);
|
|
|
|
if (desc.enumerable) names.push(symbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-18 08:39:06 +00:00
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-03 13:10:03 +00:00
|
|
|
// ES5 section 15.2.3.7.
|
2009-12-09 13:56:58 +00:00
|
|
|
function ObjectDefineProperties(obj, properties) {
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]);
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2009-12-09 13:56:58 +00:00
|
|
|
var props = ToObject(properties);
|
2011-08-18 08:39:06 +00:00
|
|
|
var names = GetOwnEnumerablePropertyNames(props);
|
2013-02-15 16:21:03 +00:00
|
|
|
var descriptors = new InternalArray();
|
2011-08-18 08:39:06 +00:00
|
|
|
for (var i = 0; i < names.length; i++) {
|
2011-10-19 09:52:08 +00:00
|
|
|
descriptors.push(ToPropertyDescriptor(props[names[i]]));
|
|
|
|
}
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
DefineOwnProperty(obj, names[i], descriptors[i], true);
|
2009-12-09 13:56:58 +00:00
|
|
|
}
|
2010-02-04 11:28:03 +00:00
|
|
|
return obj;
|
2009-12-09 13:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 13:04:52 +00:00
|
|
|
// Harmony proxies.
|
|
|
|
function ProxyFix(obj) {
|
|
|
|
var handler = %GetHandler(obj);
|
2013-10-17 10:02:45 +00:00
|
|
|
var props = CallTrap0(handler, "fix", UNDEFINED);
|
2011-07-18 13:04:52 +00:00
|
|
|
if (IS_UNDEFINED(props)) {
|
|
|
|
throw MakeTypeError("handler_returned_undefined", [handler, "fix"]);
|
|
|
|
}
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
if (%IsJSFunctionProxy(obj)) {
|
2011-09-13 11:42:57 +00:00
|
|
|
var callTrap = %GetCallTrap(obj);
|
|
|
|
var constructTrap = %GetConstructTrap(obj);
|
|
|
|
var code = DelegateCallAndConstruct(callTrap, constructTrap);
|
|
|
|
%Fix(obj); // becomes a regular function
|
|
|
|
%SetCode(obj, code);
|
2011-09-16 12:26:29 +00:00
|
|
|
// TODO(rossberg): What about length and other properties? Not specified.
|
|
|
|
// We just put in some half-reasonable defaults for now.
|
|
|
|
var prototype = new $Object();
|
|
|
|
$Object.defineProperty(prototype, "constructor",
|
2011-11-10 15:48:07 +00:00
|
|
|
{value: obj, writable: true, enumerable: false, configurable: true});
|
|
|
|
// TODO(v8:1530): defineProperty does not handle prototype and length.
|
|
|
|
%FunctionSetPrototype(obj, prototype);
|
|
|
|
obj.length = 0;
|
2011-09-13 11:42:57 +00:00
|
|
|
} else {
|
|
|
|
%Fix(obj);
|
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
ObjectDefineProperties(obj, props);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-15 07:51:14 +00:00
|
|
|
// ES5 section 15.2.3.8.
|
|
|
|
function ObjectSeal(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.seal"]);
|
2010-07-15 07:51:14 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
ProxyFix(obj);
|
|
|
|
}
|
2010-07-15 07:51:14 +00:00
|
|
|
var names = ObjectGetOwnPropertyNames(obj);
|
2010-08-26 08:35:49 +00:00
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, name);
|
2011-06-10 09:45:02 +00:00
|
|
|
if (desc.isConfigurable()) {
|
|
|
|
desc.setConfigurable(false);
|
|
|
|
DefineOwnProperty(obj, name, desc, true);
|
|
|
|
}
|
2010-10-15 13:03:59 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
%PreventExtensions(obj);
|
|
|
|
return obj;
|
2010-07-15 07:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-13 12:58:02 +00:00
|
|
|
// ES5 section 15.2.3.9.
|
2014-05-14 08:51:10 +00:00
|
|
|
function ObjectFreezeJS(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.freeze"]);
|
2010-07-13 12:58:02 +00:00
|
|
|
}
|
2013-05-23 07:05:58 +00:00
|
|
|
var isProxy = %IsJSProxy(obj);
|
2014-03-11 14:39:08 +00:00
|
|
|
if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
|
2013-05-23 07:05:58 +00:00
|
|
|
if (isProxy) {
|
|
|
|
ProxyFix(obj);
|
2013-05-22 18:53:58 +00:00
|
|
|
}
|
2013-05-23 07:05:58 +00:00
|
|
|
var names = ObjectGetOwnPropertyNames(obj);
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, name);
|
2013-05-23 07:05:58 +00:00
|
|
|
if (desc.isWritable() || desc.isConfigurable()) {
|
|
|
|
if (IsDataDescriptor(desc)) desc.setWritable(false);
|
|
|
|
desc.setConfigurable(false);
|
|
|
|
DefineOwnProperty(obj, name, desc, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%PreventExtensions(obj);
|
|
|
|
} else {
|
|
|
|
// TODO(adamk): Is it worth going to this fast path if the
|
|
|
|
// object's properties are already in dictionary mode?
|
|
|
|
%ObjectFreeze(obj);
|
2010-10-15 13:03:59 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
return obj;
|
2010-07-13 12:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-02 14:36:34 +00:00
|
|
|
// ES5 section 15.2.3.10
|
|
|
|
function ObjectPreventExtension(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]);
|
2010-07-02 14:36:34 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
ProxyFix(obj);
|
|
|
|
}
|
2010-07-02 14:36:34 +00:00
|
|
|
%PreventExtensions(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-15 07:51:14 +00:00
|
|
|
// ES5 section 15.2.3.11
|
|
|
|
function ObjectIsSealed(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.isSealed"]);
|
2010-07-15 07:51:14 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-25 19:44:21 +00:00
|
|
|
if (%IsExtensible(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-15 07:51:14 +00:00
|
|
|
var names = ObjectGetOwnPropertyNames(obj);
|
2010-08-26 08:35:49 +00:00
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, name);
|
2014-07-18 13:47:25 +00:00
|
|
|
if (desc.isConfigurable()) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-15 07:51:14 +00:00
|
|
|
}
|
2013-02-25 19:44:21 +00:00
|
|
|
return true;
|
2010-07-15 07:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-13 12:58:02 +00:00
|
|
|
// ES5 section 15.2.3.12
|
|
|
|
function ObjectIsFrozen(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]);
|
2010-07-13 12:58:02 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-25 19:44:21 +00:00
|
|
|
if (%IsExtensible(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-13 12:58:02 +00:00
|
|
|
var names = ObjectGetOwnPropertyNames(obj);
|
2010-08-26 08:35:49 +00:00
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
2014-05-14 08:51:10 +00:00
|
|
|
var desc = GetOwnPropertyJS(obj, name);
|
2010-07-14 13:15:43 +00:00
|
|
|
if (IsDataDescriptor(desc) && desc.isWritable()) return false;
|
|
|
|
if (desc.isConfigurable()) return false;
|
2010-07-13 12:58:02 +00:00
|
|
|
}
|
2013-02-25 19:44:21 +00:00
|
|
|
return true;
|
2010-07-13 12:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-02 14:36:34 +00:00
|
|
|
// ES5 section 15.2.3.13
|
|
|
|
function ObjectIsExtensible(obj) {
|
2010-07-16 11:21:08 +00:00
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
2012-03-05 13:57:48 +00:00
|
|
|
throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]);
|
2010-07-02 14:36:34 +00:00
|
|
|
}
|
2011-07-18 13:04:52 +00:00
|
|
|
if (%IsJSProxy(obj)) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-07-02 14:36:34 +00:00
|
|
|
return %IsExtensible(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-08 12:49:24 +00:00
|
|
|
// Harmony egal.
|
|
|
|
function ObjectIs(obj1, obj2) {
|
|
|
|
if (obj1 === obj2) {
|
2012-03-08 16:38:44 +00:00
|
|
|
return (obj1 !== 0) || (1 / obj1 === 1 / obj2);
|
2012-03-08 12:49:24 +00:00
|
|
|
} else {
|
|
|
|
return (obj1 !== obj1) && (obj2 !== obj2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-19 11:59:05 +00:00
|
|
|
// ECMA-262, Edition 6, section B.2.2.1.1
|
2013-04-04 12:10:23 +00:00
|
|
|
function ObjectGetProto() {
|
2014-02-19 11:59:05 +00:00
|
|
|
return %GetPrototype(ToObject(this));
|
2013-04-04 12:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-19 11:59:05 +00:00
|
|
|
// ECMA-262, Edition 6, section B.2.2.1.2
|
|
|
|
function ObjectSetProto(proto) {
|
|
|
|
CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__");
|
|
|
|
|
2014-03-05 08:58:38 +00:00
|
|
|
if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) {
|
2014-02-19 11:59:05 +00:00
|
|
|
%SetPrototype(this, proto);
|
|
|
|
}
|
2013-04-04 12:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
function ObjectConstructor(x) {
|
2009-06-29 08:14:06 +00:00
|
|
|
if (%_IsConstructCall()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
if (x == null) return this;
|
|
|
|
return ToObject(x);
|
|
|
|
} else {
|
|
|
|
if (x == null) return { };
|
|
|
|
return ToObject(x);
|
|
|
|
}
|
2013-04-11 12:15:25 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2011-09-05 07:30:35 +00:00
|
|
|
// Object
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpObject() {
|
|
|
|
%CheckIsBootstrapping();
|
2013-04-04 12:10:23 +00:00
|
|
|
|
2013-05-13 10:59:00 +00:00
|
|
|
%SetNativeFlag($Object);
|
2013-04-11 12:15:25 +00:00
|
|
|
%SetCode($Object, ObjectConstructor);
|
2013-04-04 12:10:23 +00:00
|
|
|
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty($Object.prototype, "constructor", $Object, DONT_ENUM);
|
2013-04-11 12:27:55 +00:00
|
|
|
|
2013-04-04 12:10:23 +00:00
|
|
|
// Set up non-enumerable functions on the Object.prototype object.
|
2008-10-03 18:00:28 +00:00
|
|
|
InstallFunctions($Object.prototype, DONT_ENUM, $Array(
|
|
|
|
"toString", ObjectToString,
|
|
|
|
"toLocaleString", ObjectToLocaleString,
|
|
|
|
"valueOf", ObjectValueOf,
|
|
|
|
"hasOwnProperty", ObjectHasOwnProperty,
|
|
|
|
"isPrototypeOf", ObjectIsPrototypeOf,
|
|
|
|
"propertyIsEnumerable", ObjectPropertyIsEnumerable,
|
|
|
|
"__defineGetter__", ObjectDefineGetter,
|
|
|
|
"__lookupGetter__", ObjectLookupGetter,
|
|
|
|
"__defineSetter__", ObjectDefineSetter,
|
|
|
|
"__lookupSetter__", ObjectLookupSetter
|
|
|
|
));
|
2013-04-04 12:10:23 +00:00
|
|
|
InstallGetterSetter($Object.prototype, "__proto__",
|
|
|
|
ObjectGetProto, ObjectSetProto);
|
|
|
|
|
|
|
|
// Set up non-enumerable functions in the Object object.
|
2009-09-15 11:51:40 +00:00
|
|
|
InstallFunctions($Object, DONT_ENUM, $Array(
|
2009-12-09 13:56:58 +00:00
|
|
|
"keys", ObjectKeys,
|
2010-01-07 10:01:24 +00:00
|
|
|
"create", ObjectCreate,
|
2010-02-03 13:10:03 +00:00
|
|
|
"defineProperty", ObjectDefineProperty,
|
|
|
|
"defineProperties", ObjectDefineProperties,
|
2014-05-14 08:51:10 +00:00
|
|
|
"freeze", ObjectFreezeJS,
|
2010-01-13 12:10:57 +00:00
|
|
|
"getPrototypeOf", ObjectGetPrototypeOf,
|
2014-01-22 12:15:57 +00:00
|
|
|
"setPrototypeOf", ObjectSetPrototypeOf,
|
2010-01-15 15:34:32 +00:00
|
|
|
"getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
|
2010-07-02 14:36:34 +00:00
|
|
|
"getOwnPropertyNames", ObjectGetOwnPropertyNames,
|
2014-01-09 15:57:30 +00:00
|
|
|
// getOwnPropertySymbols is added in symbol.js.
|
2012-03-08 12:49:24 +00:00
|
|
|
"is", ObjectIs,
|
2010-07-02 14:36:34 +00:00
|
|
|
"isExtensible", ObjectIsExtensible,
|
2010-07-13 12:58:02 +00:00
|
|
|
"isFrozen", ObjectIsFrozen,
|
2010-07-15 07:51:14 +00:00
|
|
|
"isSealed", ObjectIsSealed,
|
|
|
|
"preventExtensions", ObjectPreventExtension,
|
|
|
|
"seal", ObjectSeal
|
2014-01-09 15:57:30 +00:00
|
|
|
// deliverChangeRecords, getNotifier, observe and unobserve are added
|
|
|
|
// in object-observe.js.
|
2009-09-15 11:51:40 +00:00
|
|
|
));
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpObject();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Boolean
|
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
function BooleanConstructor(x) {
|
|
|
|
if (%_IsConstructCall()) {
|
|
|
|
%_SetValueOf(this, ToBoolean(x));
|
|
|
|
} else {
|
|
|
|
return ToBoolean(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function BooleanToString() {
|
2008-07-03 15:10:15 +00:00
|
|
|
// NOTE: Both Boolean objects and values can enter here as
|
|
|
|
// 'this'. This is not as dictated by ECMA-262.
|
2011-01-05 13:52:00 +00:00
|
|
|
var b = this;
|
|
|
|
if (!IS_BOOLEAN(b)) {
|
|
|
|
if (!IS_BOOLEAN_WRAPPER(b)) {
|
|
|
|
throw new $TypeError('Boolean.prototype.toString is not generic');
|
|
|
|
}
|
|
|
|
b = %_ValueOf(b);
|
|
|
|
}
|
|
|
|
return b ? 'true' : 'false';
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function BooleanValueOf() {
|
2008-07-03 15:10:15 +00:00
|
|
|
// NOTE: Both Boolean objects and values can enter here as
|
|
|
|
// 'this'. This is not as dictated by ECMA-262.
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
throw new $TypeError('Boolean.prototype.valueOf is not generic');
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return %_ValueOf(this);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpBoolean () {
|
|
|
|
%CheckIsBootstrapping();
|
2013-04-11 12:15:25 +00:00
|
|
|
|
|
|
|
%SetCode($Boolean, BooleanConstructor);
|
|
|
|
%FunctionSetPrototype($Boolean, new $Boolean(false));
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
|
2013-04-11 12:15:25 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
|
|
|
|
"toString", BooleanToString,
|
2010-12-15 09:31:05 +00:00
|
|
|
"valueOf", BooleanValueOf
|
2008-10-03 18:00:28 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpBoolean();
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Number
|
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
function NumberConstructor(x) {
|
2008-07-03 15:10:15 +00:00
|
|
|
var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x);
|
2009-06-29 08:14:06 +00:00
|
|
|
if (%_IsConstructCall()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
%_SetValueOf(this, value);
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
2013-04-11 12:15:25 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.2.
|
2008-10-03 18:00:28 +00:00
|
|
|
function NumberToString(radix) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// NOTE: Both Number objects and values can enter here as
|
|
|
|
// 'this'. This is not as dictated by ECMA-262.
|
|
|
|
var number = this;
|
|
|
|
if (!IS_NUMBER(this)) {
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_NUMBER_WRAPPER(this)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
throw new $TypeError('Number.prototype.toString is not generic');
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
// Get the value of this number in case it's an object.
|
|
|
|
number = %_ValueOf(this);
|
|
|
|
}
|
|
|
|
// Fast case: Convert number in radix 10.
|
|
|
|
if (IS_UNDEFINED(radix) || radix === 10) {
|
2011-01-05 13:52:00 +00:00
|
|
|
return %_NumberToString(number);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the radix to an integer and check the range.
|
|
|
|
radix = TO_INTEGER(radix);
|
|
|
|
if (radix < 2 || radix > 36) {
|
|
|
|
throw new $RangeError('toString() radix argument must be between 2 and 36');
|
|
|
|
}
|
|
|
|
// Convert the number to a string in the given radix.
|
|
|
|
return %NumberToRadixString(number, radix);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.3
|
2008-10-03 18:00:28 +00:00
|
|
|
function NumberToLocaleString() {
|
2012-12-07 12:18:50 +00:00
|
|
|
return %_CallFunction(this, NumberToString);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.4
|
2008-10-03 18:00:28 +00:00
|
|
|
function NumberValueOf() {
|
2008-07-03 15:10:15 +00:00
|
|
|
// NOTE: Both Number objects and values can enter here as
|
|
|
|
// 'this'. This is not as dictated by ECMA-262.
|
2011-11-28 12:11:00 +00:00
|
|
|
if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
throw new $TypeError('Number.prototype.valueOf is not generic');
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return %_ValueOf(this);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.5
|
2014-05-14 08:51:10 +00:00
|
|
|
function NumberToFixedJS(fractionDigits) {
|
2012-12-07 10:20:35 +00:00
|
|
|
var x = this;
|
|
|
|
if (!IS_NUMBER(this)) {
|
|
|
|
if (!IS_NUMBER_WRAPPER(this)) {
|
|
|
|
throw MakeTypeError("incompatible_method_receiver",
|
|
|
|
["Number.prototype.toFixed", this]);
|
|
|
|
}
|
|
|
|
// Get the value of this number in case it's an object.
|
|
|
|
x = %_ValueOf(this);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
var f = TO_INTEGER(fractionDigits);
|
2012-12-07 10:20:35 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
if (f < 0 || f > 20) {
|
|
|
|
throw new $RangeError("toFixed() digits argument must be between 0 and 20");
|
|
|
|
}
|
2012-12-07 10:20:35 +00:00
|
|
|
|
|
|
|
if (NUMBER_IS_NAN(x)) return "NaN";
|
2013-10-17 10:02:45 +00:00
|
|
|
if (x == INFINITY) return "Infinity";
|
|
|
|
if (x == -INFINITY) return "-Infinity";
|
2012-12-07 10:20:35 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return %NumberToFixed(x, f);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.6
|
2014-05-14 08:51:10 +00:00
|
|
|
function NumberToExponentialJS(fractionDigits) {
|
2012-12-07 10:20:35 +00:00
|
|
|
var x = this;
|
|
|
|
if (!IS_NUMBER(this)) {
|
|
|
|
if (!IS_NUMBER_WRAPPER(this)) {
|
|
|
|
throw MakeTypeError("incompatible_method_receiver",
|
|
|
|
["Number.prototype.toExponential", this]);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-12-07 10:20:35 +00:00
|
|
|
// Get the value of this number in case it's an object.
|
|
|
|
x = %_ValueOf(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-10-17 10:02:45 +00:00
|
|
|
var f = IS_UNDEFINED(fractionDigits) ? UNDEFINED : TO_INTEGER(fractionDigits);
|
2012-12-07 10:20:35 +00:00
|
|
|
|
|
|
|
if (NUMBER_IS_NAN(x)) return "NaN";
|
2013-10-17 10:02:45 +00:00
|
|
|
if (x == INFINITY) return "Infinity";
|
|
|
|
if (x == -INFINITY) return "-Infinity";
|
2012-12-07 10:20:35 +00:00
|
|
|
|
|
|
|
if (IS_UNDEFINED(f)) {
|
|
|
|
f = -1; // Signal for runtime function that f is not defined.
|
|
|
|
} else if (f < 0 || f > 20) {
|
|
|
|
throw new $RangeError("toExponential() argument must be between 0 and 20");
|
2011-05-05 05:21:30 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return %NumberToExponential(x, f);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262 section 15.7.4.7
|
2014-05-14 08:51:10 +00:00
|
|
|
function NumberToPrecisionJS(precision) {
|
2012-12-07 10:20:35 +00:00
|
|
|
var x = this;
|
|
|
|
if (!IS_NUMBER(this)) {
|
|
|
|
if (!IS_NUMBER_WRAPPER(this)) {
|
|
|
|
throw MakeTypeError("incompatible_method_receiver",
|
|
|
|
["Number.prototype.toPrecision", this]);
|
|
|
|
}
|
|
|
|
// Get the value of this number in case it's an object.
|
|
|
|
x = %_ValueOf(this);
|
2011-05-05 05:21:30 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this));
|
|
|
|
var p = TO_INTEGER(precision);
|
2012-12-07 10:20:35 +00:00
|
|
|
|
|
|
|
if (NUMBER_IS_NAN(x)) return "NaN";
|
2013-10-17 10:02:45 +00:00
|
|
|
if (x == INFINITY) return "Infinity";
|
|
|
|
if (x == -INFINITY) return "-Infinity";
|
2012-12-07 10:20:35 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
if (p < 1 || p > 21) {
|
|
|
|
throw new $RangeError("toPrecision() argument must be between 1 and 21");
|
|
|
|
}
|
|
|
|
return %NumberToPrecision(x, p);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-08 12:49:24 +00:00
|
|
|
// Harmony isFinite.
|
|
|
|
function NumberIsFinite(number) {
|
|
|
|
return IS_NUMBER(number) && NUMBER_IS_FINITE(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-08 09:09:49 +00:00
|
|
|
// Harmony isInteger
|
|
|
|
function NumberIsInteger(number) {
|
|
|
|
return NumberIsFinite(number) && TO_INTEGER(number) == number;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-08 12:49:24 +00:00
|
|
|
// Harmony isNaN.
|
|
|
|
function NumberIsNaN(number) {
|
|
|
|
return IS_NUMBER(number) && NUMBER_IS_NAN(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-08 09:09:49 +00:00
|
|
|
// Harmony isSafeInteger
|
|
|
|
function NumberIsSafeInteger(number) {
|
|
|
|
if (NumberIsFinite(number)) {
|
|
|
|
var integral = TO_INTEGER(number);
|
|
|
|
if (integral == number)
|
|
|
|
return MathAbs(integral) <= $Number.MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpNumber() {
|
|
|
|
%CheckIsBootstrapping();
|
2013-04-11 12:15:25 +00:00
|
|
|
|
|
|
|
%SetCode($Number, NumberConstructor);
|
|
|
|
%FunctionSetPrototype($Number, new $Number(0));
|
|
|
|
|
2009-08-13 12:35:59 +00:00
|
|
|
%OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up the constructor property on the Number prototype object.
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
|
2008-10-03 18:00:28 +00:00
|
|
|
|
2014-01-08 09:09:49 +00:00
|
|
|
InstallConstants($Number, $Array(
|
|
|
|
// ECMA-262 section 15.7.3.1.
|
|
|
|
"MAX_VALUE", 1.7976931348623157e+308,
|
|
|
|
// ECMA-262 section 15.7.3.2.
|
|
|
|
"MIN_VALUE", 5e-324,
|
|
|
|
// ECMA-262 section 15.7.3.3.
|
|
|
|
"NaN", NAN,
|
|
|
|
// ECMA-262 section 15.7.3.4.
|
|
|
|
"NEGATIVE_INFINITY", -INFINITY,
|
|
|
|
// ECMA-262 section 15.7.3.5.
|
|
|
|
"POSITIVE_INFINITY", INFINITY,
|
|
|
|
|
|
|
|
// --- Harmony constants (no spec refs until settled.)
|
|
|
|
|
|
|
|
"MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1,
|
|
|
|
"MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1,
|
|
|
|
"EPSILON", %_MathPow(2, -52)
|
|
|
|
));
|
2008-10-03 18:00:28 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up non-enumerable functions on the Number prototype object.
|
2008-10-03 18:00:28 +00:00
|
|
|
InstallFunctions($Number.prototype, DONT_ENUM, $Array(
|
|
|
|
"toString", NumberToString,
|
|
|
|
"toLocaleString", NumberToLocaleString,
|
|
|
|
"valueOf", NumberValueOf,
|
2014-05-14 08:51:10 +00:00
|
|
|
"toFixed", NumberToFixedJS,
|
|
|
|
"toExponential", NumberToExponentialJS,
|
|
|
|
"toPrecision", NumberToPrecisionJS
|
2008-10-03 18:00:28 +00:00
|
|
|
));
|
2014-01-08 09:09:49 +00:00
|
|
|
|
|
|
|
// Harmony Number constructor additions
|
2012-03-08 12:49:24 +00:00
|
|
|
InstallFunctions($Number, DONT_ENUM, $Array(
|
|
|
|
"isFinite", NumberIsFinite,
|
2014-01-08 09:09:49 +00:00
|
|
|
"isInteger", NumberIsInteger,
|
|
|
|
"isNaN", NumberIsNaN,
|
|
|
|
"isSafeInteger", NumberIsSafeInteger,
|
|
|
|
"parseInt", GlobalParseInt,
|
|
|
|
"parseFloat", GlobalParseFloat
|
2012-03-08 12:49:24 +00:00
|
|
|
));
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpNumber();
|
2008-10-03 18:00:28 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Function
|
|
|
|
|
|
|
|
function FunctionSourceString(func) {
|
2011-09-13 11:42:57 +00:00
|
|
|
while (%IsJSFunctionProxy(func)) {
|
|
|
|
func = %GetCallTrap(func);
|
|
|
|
}
|
|
|
|
|
2009-06-29 10:45:16 +00:00
|
|
|
if (!IS_FUNCTION(func)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
throw new $TypeError('Function.prototype.toString is not generic');
|
2009-06-29 10:45:16 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
var source = %FunctionGetSourceCode(func);
|
2009-09-17 11:11:01 +00:00
|
|
|
if (!IS_STRING(source) || %FunctionIsBuiltin(func)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
var name = %FunctionGetName(func);
|
|
|
|
if (name) {
|
|
|
|
// Mimic what KJS does.
|
|
|
|
return 'function ' + name + '() { [native code] }';
|
|
|
|
} else {
|
|
|
|
return 'function () { [native code] }';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 09:58:01 +00:00
|
|
|
if (%FunctionIsArrow(func)) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2011-08-08 16:14:46 +00:00
|
|
|
var name = %FunctionNameShouldPrintAsAnonymous(func)
|
|
|
|
? 'anonymous'
|
|
|
|
: %FunctionGetName(func);
|
2014-09-10 16:39:42 +00:00
|
|
|
|
2014-09-18 17:14:13 +00:00
|
|
|
var isGenerator = %FunctionIsGenerator(func);
|
2014-09-10 16:39:42 +00:00
|
|
|
var head = %FunctionIsConciseMethod(func)
|
2014-09-18 17:14:13 +00:00
|
|
|
? (isGenerator ? '*' : '')
|
|
|
|
: (isGenerator ? 'function* ' : 'function ');
|
2013-05-03 13:01:28 +00:00
|
|
|
return head + name + source;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
function FunctionToString() {
|
2008-07-03 15:10:15 +00:00
|
|
|
return FunctionSourceString(this);
|
2008-10-03 18:00:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-07-23 10:08:55 +00:00
|
|
|
// ES5 15.3.4.5
|
|
|
|
function FunctionBind(this_arg) { // Length is 1.
|
2011-09-13 11:42:57 +00:00
|
|
|
if (!IS_SPEC_FUNCTION(this)) {
|
2011-10-17 12:44:16 +00:00
|
|
|
throw new $TypeError('Bind must be called on a function');
|
|
|
|
}
|
|
|
|
var boundFunction = function () {
|
2011-10-18 12:26:53 +00:00
|
|
|
// Poison .arguments and .caller, but is otherwise not detectable.
|
|
|
|
"use strict";
|
2011-10-17 12:44:16 +00:00
|
|
|
// This function must not use any object literals (Object, Array, RegExp),
|
|
|
|
// since the literals-array is being used to store the bound data.
|
|
|
|
if (%_IsConstructCall()) {
|
|
|
|
return %NewObjectFromBound(boundFunction);
|
2010-10-15 13:03:59 +00:00
|
|
|
}
|
2011-10-17 12:44:16 +00:00
|
|
|
var bindings = %BoundFunctionGetBindings(boundFunction);
|
2011-02-08 10:08:47 +00:00
|
|
|
|
2011-10-17 12:44:16 +00:00
|
|
|
var argc = %_ArgumentsLength();
|
|
|
|
if (argc == 0) {
|
|
|
|
return %Apply(bindings[0], bindings[1], bindings, 2, bindings.length - 2);
|
|
|
|
}
|
|
|
|
if (bindings.length === 2) {
|
|
|
|
return %Apply(bindings[0], bindings[1], arguments, 0, argc);
|
|
|
|
}
|
|
|
|
var bound_argc = bindings.length - 2;
|
|
|
|
var argv = new InternalArray(bound_argc + argc);
|
|
|
|
for (var i = 0; i < bound_argc; i++) {
|
|
|
|
argv[i] = bindings[i + 2];
|
|
|
|
}
|
|
|
|
for (var j = 0; j < argc; j++) {
|
|
|
|
argv[i++] = %_Arguments(j);
|
|
|
|
}
|
|
|
|
return %Apply(bindings[0], bindings[1], argv, 0, bound_argc + argc);
|
|
|
|
};
|
|
|
|
|
|
|
|
var new_length = 0;
|
2014-06-13 12:19:04 +00:00
|
|
|
var old_length = this.length;
|
|
|
|
// FunctionProxies might provide a non-UInt32 value. If so, ignore it.
|
|
|
|
if ((typeof old_length === "number") &&
|
|
|
|
((old_length >>> 0) === old_length)) {
|
|
|
|
var argc = %_ArgumentsLength();
|
|
|
|
if (argc > 0) argc--; // Don't count the thisArg as parameter.
|
|
|
|
new_length = old_length - argc;
|
|
|
|
if (new_length < 0) new_length = 0;
|
2010-07-23 10:08:55 +00:00
|
|
|
}
|
2011-10-17 12:44:16 +00:00
|
|
|
// This runtime function finds any remaining arguments on the stack,
|
|
|
|
// so we don't pass the arguments object.
|
2011-11-28 12:11:00 +00:00
|
|
|
var result = %FunctionBindArguments(boundFunction, this,
|
|
|
|
this_arg, new_length);
|
2010-07-23 10:08:55 +00:00
|
|
|
|
|
|
|
// We already have caller and arguments properties on functions,
|
|
|
|
// which are non-configurable. It therefore makes no sence to
|
|
|
|
// try to redefine these as defined by the spec. The spec says
|
|
|
|
// that bind should make these throw a TypeError if get or set
|
|
|
|
// is called and make them non-enumerable and non-configurable.
|
2010-10-15 13:03:59 +00:00
|
|
|
// To be consistent with our normal functions we leave this as it is.
|
2011-10-17 12:44:16 +00:00
|
|
|
// TODO(lrn): Do set these to be thrower.
|
2010-07-23 10:08:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-12 12:52:16 +00:00
|
|
|
function NewFunctionString(arguments, function_token) {
|
|
|
|
var n = arguments.length;
|
2008-07-03 15:10:15 +00:00
|
|
|
var p = '';
|
|
|
|
if (n > 1) {
|
2013-06-12 12:52:16 +00:00
|
|
|
p = ToString(arguments[0]);
|
|
|
|
for (var i = 1; i < n - 1; i++) {
|
|
|
|
p += ',' + ToString(arguments[i]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the formal parameters string include ) - an illegal
|
|
|
|
// character - it may make the combined function expression
|
|
|
|
// compile. We avoid this problem by checking for this early on.
|
2014-05-14 08:51:10 +00:00
|
|
|
if (%_CallFunction(p, ')', StringIndexOfJS) != -1) {
|
2013-06-12 12:52:16 +00:00
|
|
|
throw MakeSyntaxError('paren_in_arg_string', []);
|
2013-05-15 10:52:06 +00:00
|
|
|
}
|
2013-03-07 15:46:14 +00:00
|
|
|
// If the formal parameters include an unbalanced block comment, the
|
|
|
|
// function must be rejected. Since JavaScript does not allow nested
|
|
|
|
// comments we can include a trailing block comment to catch this.
|
|
|
|
p += '\n/' + '**/';
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-06-12 12:52:16 +00:00
|
|
|
var body = (n > 0) ? ToString(arguments[n - 1]) : '';
|
|
|
|
return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-12 12:52:16 +00:00
|
|
|
|
|
|
|
function FunctionConstructor(arg1) { // length == 1
|
|
|
|
var source = NewFunctionString(arguments, 'function');
|
2014-07-01 12:12:34 +00:00
|
|
|
var global_proxy = %GlobalProxy(global);
|
2013-06-12 12:52:16 +00:00
|
|
|
// Compile the string in the constructor and not a helper so that errors
|
|
|
|
// appear to come from here.
|
2014-09-18 17:25:25 +00:00
|
|
|
var f = %_CallFunction(global_proxy, %CompileString(source, true));
|
2011-08-08 16:14:46 +00:00
|
|
|
%FunctionMarkNameShouldPrintAsAnonymous(f);
|
2013-05-10 12:59:20 +00:00
|
|
|
return f;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpFunction() {
|
|
|
|
%CheckIsBootstrapping();
|
2013-04-11 12:15:25 +00:00
|
|
|
|
2013-06-12 12:52:16 +00:00
|
|
|
%SetCode($Function, FunctionConstructor);
|
2014-07-14 14:05:30 +00:00
|
|
|
%AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
|
2013-04-11 12:15:25 +00:00
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
InstallFunctions($Function.prototype, DONT_ENUM, $Array(
|
2010-07-23 10:08:55 +00:00
|
|
|
"bind", FunctionBind,
|
2008-10-03 18:00:28 +00:00
|
|
|
"toString", FunctionToString
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpFunction();
|
2014-08-08 13:39:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Iterator related spec functions.
|
|
|
|
|
|
|
|
// ES6 rev 26, 2014-07-18
|
|
|
|
// 7.4.1 CheckIterable ( obj )
|
|
|
|
function ToIterable(obj) {
|
|
|
|
if (!IS_SPEC_OBJECT(obj)) {
|
|
|
|
return UNDEFINED;
|
|
|
|
}
|
|
|
|
return obj[symbolIterator];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ES6 rev 26, 2014-07-18
|
|
|
|
// 7.4.2 GetIterator ( obj, method )
|
|
|
|
function GetIterator(obj, method) {
|
|
|
|
if (IS_UNDEFINED(method)) {
|
|
|
|
method = ToIterable(obj);
|
|
|
|
}
|
|
|
|
if (!IS_SPEC_FUNCTION(method)) {
|
|
|
|
throw MakeTypeError('not_iterable', [obj]);
|
|
|
|
}
|
|
|
|
var iterator = %_CallFunction(obj, method);
|
|
|
|
if (!IS_SPEC_OBJECT(iterator)) {
|
|
|
|
throw MakeTypeError('not_an_iterator', [iterator]);
|
|
|
|
}
|
|
|
|
return iterator;
|
|
|
|
}
|