Index: src/v8natives.js |
diff --git a/src/v8natives.js b/src/v8natives.js |
index 834b41ce82efcfb4e9f8a84752116e4ee446b612..180c05e1ebc81c4385dba9e6a347f0863ee93d47 100644 |
--- a/src/v8natives.js |
+++ b/src/v8natives.js |
@@ -2,10 +2,35 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+var $delete; |
var $functionSourceString; |
+var $getIterator; |
+var $getMethod; |
var $globalEval; |
+var $installConstants; |
+var $installFunctions; |
+var $installGetter; |
+var $isFinite; |
+var $isNaN; |
+var $newFunctionString; |
+var $numberIsNaN; |
+var $objectDefineProperties; |
+var $objectDefineProperty; |
+var $objectFreeze; |
var $objectGetOwnPropertyDescriptor; |
+var $objectGetOwnPropertyKeys; |
+var $objectHasOwnProperty; |
+var $objectIsFrozen; |
+var $objectIsSealed; |
+var $objectLookupGetter; |
+var $objectLookupSetter; |
+var $objectToString; |
+var $overrideFunction; |
+var $ownPropertyKeys; |
+var $setFunctionName; |
+var $setUpLockedPrototype; |
var $toCompletePropertyDescriptor; |
+var $toNameArray; |
(function(global, utils) { |
@@ -22,9 +47,6 @@ |
var InternalArray = utils.InternalArray; |
var MathAbs; |
-var ProxyDelegateCallAndConstruct; |
-var ProxyDerivedHasOwnTrap; |
-var ProxyDerivedKeysTrap; |
var StringIndexOf; |
utils.Import(function(from) { |
@@ -32,11 +54,113 @@ |
StringIndexOf = from.StringIndexOf; |
}); |
-utils.ImportFromExperimental(function(from) { |
- ProxyDelegateCallAndConstruct = from.ProxyDelegateCallAndConstruct; |
- ProxyDerivedHasOwnTrap = from.ProxyDerivedHasOwnTrap; |
- ProxyDerivedKeysTrap = from.ProxyDerivedKeysTrap; |
-}); |
+// ---------------------------------------------------------------------------- |
+ |
+// ES6 - 9.2.11 SetFunctionName |
+function SetFunctionName(f, name, prefix) { |
+ if (IS_SYMBOL(name)) { |
+ name = "[" + %SymbolDescription(name) + "]"; |
+ } |
+ if (IS_UNDEFINED(prefix)) { |
+ %FunctionSetName(f, name); |
+ } else { |
+ %FunctionSetName(f, prefix + " " + name); |
+ } |
+} |
+ |
+ |
+// Helper function used to install functions on objects. |
+function InstallFunctions(object, attributes, functions) { |
+ %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); |
+ for (var i = 0; i < functions.length; i += 2) { |
+ var key = functions[i]; |
+ var f = functions[i + 1]; |
+ SetFunctionName(f, key); |
+ %FunctionRemovePrototype(f); |
+ %AddNamedProperty(object, key, f, attributes); |
+ %SetNativeFlag(f); |
+ } |
+ %ToFastProperties(object); |
+} |
+ |
+ |
+function OverrideFunction(object, name, f) { |
+ ObjectDefineProperty(object, name, { value: f, |
+ writeable: true, |
+ configurable: true, |
+ enumerable: false }); |
+ SetFunctionName(f, name); |
+ %FunctionRemovePrototype(f); |
+ %SetNativeFlag(f); |
+} |
+ |
+ |
+// Helper function to install a getter-only accessor property. |
+function InstallGetter(object, name, getter, attributes) { |
+ if (typeof attributes == "undefined") { |
+ attributes = DONT_ENUM; |
+ } |
+ SetFunctionName(getter, name, "get"); |
+ %FunctionRemovePrototype(getter); |
+ %DefineAccessorPropertyUnchecked(object, name, getter, null, attributes); |
+ %SetNativeFlag(getter); |
+} |
+ |
+ |
+// Helper function to install a getter/setter accessor property. |
+function InstallGetterSetter(object, name, getter, setter) { |
+ SetFunctionName(getter, name, "get"); |
+ SetFunctionName(setter, name, "set"); |
+ %FunctionRemovePrototype(getter); |
+ %FunctionRemovePrototype(setter); |
+ %DefineAccessorPropertyUnchecked(object, name, getter, setter, DONT_ENUM); |
+ %SetNativeFlag(getter); |
+ %SetNativeFlag(setter); |
+} |
+ |
+ |
+// Helper function for installing constant properties on objects. |
+function InstallConstants(object, constants) { |
+ %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]; |
+ %AddNamedProperty(object, name, k, attributes); |
+ } |
+ %ToFastProperties(object); |
+} |
+ |
+ |
+// Prevents changes to the prototype of a built-in function. |
+// 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++) { |
+ %AddNamedProperty(prototype, fields[i], |
+ UNDEFINED, DONT_ENUM | DONT_DELETE); |
+ } |
+ } |
+ for (var i = 0; i < methods.length; i += 2) { |
+ var key = methods[i]; |
+ var f = methods[i + 1]; |
+ %AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
+ %SetNativeFlag(f); |
+ } |
+ %InternalSetPrototype(prototype, null); |
+ %ToFastProperties(prototype); |
+} |
+ |
// ---------------------------------------------------------------------------- |
@@ -114,7 +238,7 @@ |
// Set up global object. |
var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
-utils.InstallConstants(global, [ |
+InstallConstants(global, [ |
// ECMA 262 - 15.1.1.1. |
"NaN", NAN, |
// ECMA-262 - 15.1.1.2. |
@@ -124,7 +248,7 @@ |
]); |
// Set up non-enumerable function on the global object. |
-utils.InstallFunctions(global, DONT_ENUM, [ |
+InstallFunctions(global, DONT_ENUM, [ |
"isNaN", GlobalIsNaN, |
"isFinite", GlobalIsFinite, |
"parseInt", GlobalParseInt, |
@@ -178,7 +302,7 @@ |
if (IS_SYMBOL(V)) return false; |
var handler = %GetHandler(this); |
- return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, $toName(V)); |
+ return CallTrap1(handler, "hasOwn", $proxyDerivedHasOwnTrap, $toName(V)); |
} |
return %HasOwnProperty(TO_OBJECT_INLINE(this), $toName(V)); |
} |
@@ -261,7 +385,7 @@ |
obj = TO_OBJECT_INLINE(obj); |
if (%_IsJSProxy(obj)) { |
var handler = %GetHandler(obj); |
- var names = CallTrap0(handler, "keys", ProxyDerivedKeysTrap); |
+ var names = CallTrap0(handler, "keys", $proxyDerivedKeysTrap); |
return ToNameArray(names, "keys", false); |
} |
return %OwnKeys(obj); |
@@ -418,7 +542,7 @@ |
this.hasSetter_ = false; |
} |
-utils.SetUpLockedPrototype(PropertyDescriptor, [ |
+SetUpLockedPrototype(PropertyDescriptor, [ |
"value_", |
"hasValue_", |
"writable_", |
@@ -1162,7 +1286,7 @@ |
if (%IsJSFunctionProxy(obj)) { |
var callTrap = %GetCallTrap(obj); |
var constructTrap = %GetConstructTrap(obj); |
- var code = ProxyDelegateCallAndConstruct(callTrap, constructTrap); |
+ var code = $proxyDelegateCallAndConstruct(callTrap, constructTrap); |
%Fix(obj); // becomes a regular function |
%SetCode(obj, code); |
// TODO(rossberg): What about length and other properties? Not specified. |
@@ -1340,7 +1464,7 @@ |
DONT_ENUM); |
// Set up non-enumerable functions on the Object.prototype object. |
-utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ |
+InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ |
"toString", ObjectToString, |
"toLocaleString", ObjectToLocaleString, |
"valueOf", ObjectValueOf, |
@@ -1352,11 +1476,11 @@ |
"__defineSetter__", ObjectDefineSetter, |
"__lookupSetter__", ObjectLookupSetter |
]); |
-utils.InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto, |
+InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto, |
ObjectSetProto); |
// Set up non-enumerable functions in the Object object. |
-utils.InstallFunctions(GlobalObject, DONT_ENUM, [ |
+InstallFunctions(GlobalObject, DONT_ENUM, [ |
"keys", ObjectKeys, |
"create", ObjectCreate, |
"defineProperty", ObjectDefineProperty, |
@@ -1421,7 +1545,7 @@ |
%AddNamedProperty(GlobalBoolean.prototype, "constructor", GlobalBoolean, |
DONT_ENUM); |
-utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ |
+InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ |
"toString", BooleanToString, |
"valueOf", BooleanValueOf |
]); |
@@ -1598,7 +1722,7 @@ |
%AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber, |
DONT_ENUM); |
-utils.InstallConstants(GlobalNumber, [ |
+InstallConstants(GlobalNumber, [ |
// ECMA-262 section 15.7.3.1. |
"MAX_VALUE", 1.7976931348623157e+308, |
// ECMA-262 section 15.7.3.2. |
@@ -1618,7 +1742,7 @@ |
]); |
// Set up non-enumerable functions on the Number prototype object. |
-utils.InstallFunctions(GlobalNumber.prototype, DONT_ENUM, [ |
+InstallFunctions(GlobalNumber.prototype, DONT_ENUM, [ |
"toString", NumberToStringJS, |
"toLocaleString", NumberToLocaleString, |
"valueOf", NumberValueOf, |
@@ -1628,7 +1752,7 @@ |
]); |
// Harmony Number constructor additions |
-utils.InstallFunctions(GlobalNumber, DONT_ENUM, [ |
+InstallFunctions(GlobalNumber, DONT_ENUM, [ |
"isFinite", NumberIsFinite, |
"isInteger", NumberIsInteger, |
"isNaN", NumberIsNaN, |
@@ -1796,7 +1920,7 @@ |
%AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction, |
DONT_ENUM); |
-utils.InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ |
+InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ |
"bind", FunctionBind, |
"toString", FunctionToString |
]); |
@@ -1820,34 +1944,36 @@ |
return iterator; |
} |
-// ---------------------------------------------------------------------------- |
-// Exports |
- |
+//---------------------------------------------------------------------------- |
+ |
+$delete = Delete; |
$functionSourceString = FunctionSourceString; |
+$getIterator = GetIterator; |
+$getMethod = GetMethod; |
$globalEval = GlobalEval; |
+$installConstants = InstallConstants; |
+$installFunctions = InstallFunctions; |
+$installGetter = InstallGetter; |
+$isFinite = GlobalIsFinite; |
+$isNaN = GlobalIsNaN; |
+$newFunctionString = NewFunctionString; |
+$numberIsNaN = NumberIsNaN; |
+$objectDefineProperties = ObjectDefineProperties; |
+$objectDefineProperty = ObjectDefineProperty; |
+$objectFreeze = ObjectFreezeJS; |
$objectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor; |
+$objectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; |
+$objectHasOwnProperty = ObjectHasOwnProperty; |
+$objectIsFrozen = ObjectIsFrozen; |
+$objectIsSealed = ObjectIsSealed; |
+$objectLookupGetter = ObjectLookupGetter; |
+$objectLookupSetter = ObjectLookupSetter; |
+$objectToString = ObjectToString; |
+$overrideFunction = OverrideFunction; |
+$ownPropertyKeys = OwnPropertyKeys; |
+$setFunctionName = SetFunctionName; |
+$setUpLockedPrototype = SetUpLockedPrototype; |
$toCompletePropertyDescriptor = ToCompletePropertyDescriptor; |
- |
-utils.ObjectDefineProperties = ObjectDefineProperties; |
-utils.ObjectDefineProperty = ObjectDefineProperty; |
- |
-utils.Export(function(to) { |
- to.Delete = Delete; |
- to.GetIterator = GetIterator; |
- to.GetMethod = GetMethod; |
- to.IsFinite = GlobalIsFinite; |
- to.IsNaN = GlobalIsNaN; |
- to.NewFunctionString = NewFunctionString; |
- to.NumberIsNaN = NumberIsNaN; |
- to.ObjectDefineProperty = ObjectDefineProperty; |
- to.ObjectFreeze = ObjectFreezeJS; |
- to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; |
- to.ObjectHasOwnProperty = ObjectHasOwnProperty; |
- to.ObjectIsFrozen = ObjectIsFrozen; |
- to.ObjectIsSealed = ObjectIsSealed; |
- to.ObjectToString = ObjectToString; |
- to.OwnPropertyKeys = OwnPropertyKeys; |
- to.ToNameArray = ToNameArray; |
-}); |
+$toNameArray = ToNameArray; |
}) |