Index: src/v8natives.js |
diff --git a/src/v8natives.js b/src/v8natives.js |
index 5f870c8208f7c2add547a7d5ab378e11498958e8..754fdd6fc7d34c0b5864006d3cd0945c6b960f4a 100644 |
--- a/src/v8natives.js |
+++ b/src/v8natives.js |
@@ -26,7 +26,6 @@ |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// This file relies on the fact that the following declarations have been made |
-// |
// in runtime.js: |
// var $Object = global.Object; |
// var $Boolean = global.Boolean; |
@@ -43,7 +42,6 @@ var $isFinite = GlobalIsFinite; |
// ---------------------------------------------------------------------------- |
- |
// Helper function used to install functions on objects. |
function InstallFunctions(object, attributes, functions) { |
if (functions.length >= 8) { |
@@ -198,6 +196,7 @@ function GlobalEval(x) { |
// Set up global object. |
function SetUpGlobal() { |
%CheckIsBootstrapping(); |
+ |
// ECMA 262 - 15.1.1.1. |
%SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); |
@@ -220,27 +219,10 @@ function SetUpGlobal() { |
SetUpGlobal(); |
-// ---------------------------------------------------------------------------- |
-// Boolean (first part of definition) |
- |
- |
-%SetCode($Boolean, function(x) { |
- if (%_IsConstructCall()) { |
- %_SetValueOf(this, ToBoolean(x)); |
- } else { |
- return ToBoolean(x); |
- } |
-}); |
- |
-%FunctionSetPrototype($Boolean, new $Boolean(false)); |
- |
-%SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
// ---------------------------------------------------------------------------- |
// Object |
-$Object.prototype.constructor = $Object; |
- |
// ECMA-262 - 15.2.4.2 |
function ObjectToString() { |
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
@@ -1357,7 +1339,7 @@ function ObjectPoisonProto(obj) { |
} |
-%SetCode($Object, function(x) { |
+function ObjectConstructor(x) { |
if (%_IsConstructCall()) { |
if (x == null) return this; |
return ToObject(x); |
@@ -1365,7 +1347,7 @@ function ObjectPoisonProto(obj) { |
if (x == null) return { }; |
return ToObject(x); |
} |
-}); |
+} |
// ---------------------------------------------------------------------------- |
@@ -1374,6 +1356,8 @@ function ObjectPoisonProto(obj) { |
function SetUpObject() { |
%CheckIsBootstrapping(); |
+ $Object.prototype.constructor = $Object; |
+ %SetCode($Object, ObjectConstructor); |
%FunctionSetName(ObjectPoisonProto, "__proto__"); |
%FunctionRemovePrototype(ObjectPoisonProto); |
%SetExpectedNumberOfProperties($Object, 4); |
@@ -1415,9 +1399,19 @@ function SetUpObject() { |
SetUpObject(); |
+ |
// ---------------------------------------------------------------------------- |
// Boolean |
+function BooleanConstructor(x) { |
+ if (%_IsConstructCall()) { |
+ %_SetValueOf(this, ToBoolean(x)); |
+ } else { |
+ return ToBoolean(x); |
+ } |
+} |
+ |
+ |
function BooleanToString() { |
// NOTE: Both Boolean objects and values can enter here as |
// 'this'. This is not as dictated by ECMA-262. |
@@ -1444,9 +1438,13 @@ function BooleanValueOf() { |
// ---------------------------------------------------------------------------- |
- |
function SetUpBoolean () { |
%CheckIsBootstrapping(); |
+ |
+ %SetCode($Boolean, BooleanConstructor); |
+ %FunctionSetPrototype($Boolean, new $Boolean(false)); |
+ %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
+ |
InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
"toString", BooleanToString, |
"valueOf", BooleanValueOf |
@@ -1459,17 +1457,15 @@ SetUpBoolean(); |
// ---------------------------------------------------------------------------- |
// Number |
-// Set the Number function and constructor. |
-%SetCode($Number, function(x) { |
+function NumberConstructor(x) { |
var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); |
if (%_IsConstructCall()) { |
%_SetValueOf(this, value); |
} else { |
return value; |
} |
-}); |
+} |
-%FunctionSetPrototype($Number, new $Number(0)); |
// ECMA-262 section 15.7.4.2. |
function NumberToString(radix) { |
@@ -1607,6 +1603,10 @@ function NumberIsNaN(number) { |
function SetUpNumber() { |
%CheckIsBootstrapping(); |
+ |
+ %SetCode($Number, NumberConstructor); |
+ %FunctionSetPrototype($Number, new $Number(0)); |
+ |
%OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
// Set up the constructor property on the Number prototype object. |
%SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
@@ -1659,8 +1659,6 @@ SetUpNumber(); |
// ---------------------------------------------------------------------------- |
// Function |
-$Function.prototype.constructor = $Function; |
- |
function FunctionSourceString(func) { |
while (%IsJSFunctionProxy(func)) { |
func = %GetCallTrap(func); |
@@ -1784,12 +1782,15 @@ function NewFunction(arg1) { // length == 1 |
return %SetNewFunctionAttributes(f); |
} |
-%SetCode($Function, NewFunction); |
// ---------------------------------------------------------------------------- |
function SetUpFunction() { |
%CheckIsBootstrapping(); |
+ |
+ $Function.prototype.constructor = $Function; |
+ %SetCode($Function, NewFunction); |
+ |
InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
"bind", FunctionBind, |
"toString", FunctionToString |