Move global code for builtins into setup functions.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/14125004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14228 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 714113b2
...@@ -1454,8 +1454,10 @@ function ArrayIsArray(obj) { ...@@ -1454,8 +1454,10 @@ function ArrayIsArray(obj) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SetUpArray() { function SetUpArray() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set up non-enumerable constructor property on the Array.prototype // Set up non-enumerable constructor property on the Array.prototype
// object. // object.
%SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM); %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM);
......
...@@ -27,16 +27,20 @@ ...@@ -27,16 +27,20 @@
"use strict"; "use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
var $Set = global.Set; var $Set = global.Set;
var $Map = global.Map; var $Map = global.Map;
var $WeakMap = global.WeakMap; var $WeakMap = global.WeakMap;
//-------------------------------------------------------------------
// Global sentinel to be used instead of undefined keys, which are not // Global sentinel to be used instead of undefined keys, which are not
// supported internally but required for Harmony sets and maps. // supported internally but required for Harmony sets and maps.
var undefined_sentinel = {}; var undefined_sentinel = {};
// -------------------------------------------------------------------
// Harmony Set
function SetConstructor() { function SetConstructor() {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
...@@ -107,6 +111,30 @@ function SetClear() { ...@@ -107,6 +111,30 @@ function SetClear() {
} }
// -------------------------------------------------------------------
function SetUpSet() {
%CheckIsBootstrapping();
%SetCode($Set, SetConstructor);
%SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
// Set up the non-enumerable functions on the Set prototype object.
InstallGetter($Set.prototype, "size", SetGetSize);
InstallFunctions($Set.prototype, DONT_ENUM, $Array(
"add", SetAdd,
"has", SetHas,
"delete", SetDelete,
"clear", SetClear
));
}
SetUpSet();
// -------------------------------------------------------------------
// Harmony Map
function MapConstructor() { function MapConstructor() {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%MapInitialize(this); %MapInitialize(this);
...@@ -183,6 +211,31 @@ function MapClear() { ...@@ -183,6 +211,31 @@ function MapClear() {
} }
// -------------------------------------------------------------------
function SetUpMap() {
%CheckIsBootstrapping();
%SetCode($Map, MapConstructor);
%SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
// Set up the non-enumerable functions on the Map prototype object.
InstallGetter($Map.prototype, "size", MapGetSize);
InstallFunctions($Map.prototype, DONT_ENUM, $Array(
"get", MapGet,
"set", MapSet,
"has", MapHas,
"delete", MapDelete,
"clear", MapClear
));
}
SetUpMap();
// -------------------------------------------------------------------
// Harmony WeakMap
function WeakMapConstructor() { function WeakMapConstructor() {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%WeakMapInitialize(this); %WeakMapInitialize(this);
...@@ -239,42 +292,13 @@ function WeakMapDelete(key) { ...@@ -239,42 +292,13 @@ function WeakMapDelete(key) {
return %WeakMapDelete(this, key); return %WeakMapDelete(this, key);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
(function () { function SetUpWeakMap() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set up the Set and Map constructor function.
%SetCode($Set, SetConstructor);
%SetCode($Map, MapConstructor);
// Set up the constructor property on the Set and Map prototype object.
%SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
%SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
// Set up the non-enumerable functions on the Set prototype object.
InstallGetter($Set.prototype, "size", SetGetSize);
InstallFunctions($Set.prototype, DONT_ENUM, $Array(
"add", SetAdd,
"has", SetHas,
"delete", SetDelete,
"clear", SetClear
));
// Set up the non-enumerable functions on the Map prototype object.
InstallGetter($Map.prototype, "size", MapGetSize);
InstallFunctions($Map.prototype, DONT_ENUM, $Array(
"get", MapGet,
"set", MapSet,
"has", MapHas,
"delete", MapDelete,
"clear", MapClear
));
// Set up the WeakMap constructor function.
%SetCode($WeakMap, WeakMapConstructor); %SetCode($WeakMap, WeakMapConstructor);
// Set up the constructor property on the WeakMap prototype object.
%SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
// Set up the non-enumerable functions on the WeakMap prototype object. // Set up the non-enumerable functions on the WeakMap prototype object.
...@@ -284,4 +308,6 @@ function WeakMapDelete(key) { ...@@ -284,4 +308,6 @@ function WeakMapDelete(key) {
"has", WeakMapHas, "has", WeakMapHas,
"delete", WeakMapDelete "delete", WeakMapDelete
)); ));
})(); }
SetUpWeakMap();
...@@ -25,20 +25,16 @@ ...@@ -25,20 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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 // This file relies on the fact that the following declarations have been made
// in v8natives.js: // in v8natives.js:
// var $isFinite = GlobalIsFinite; // var $isFinite = GlobalIsFinite;
var $Date = global.Date;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// This file contains date support implemented in JavaScript. // This file contains date support implemented in JavaScript.
// Keep reference to original values of some global properties. This
// has the added benefit that the code in this file is isolated from
// changes to these properties.
var $Date = global.Date;
// Helper function to throw error. // Helper function to throw error.
function ThrowDateTypeError() { function ThrowDateTypeError() {
throw new $TypeError('this is not a Date object.'); throw new $TypeError('this is not a Date object.');
...@@ -142,7 +138,7 @@ var Date_cache = { ...@@ -142,7 +138,7 @@ var Date_cache = {
}; };
%SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { function DateConstructor(year, month, date, hours, minutes, seconds, ms) {
if (!%_IsConstructCall()) { if (!%_IsConstructCall()) {
// ECMA 262 - 15.9.2 // ECMA 262 - 15.9.2
return (new $Date()).toString(); return (new $Date()).toString();
...@@ -199,10 +195,7 @@ var Date_cache = { ...@@ -199,10 +195,7 @@ var Date_cache = {
value = MakeDate(day, time); value = MakeDate(day, time);
SET_LOCAL_DATE_VALUE(this, value); SET_LOCAL_DATE_VALUE(this, value);
} }
}); }
%FunctionSetPrototype($Date, new $Date($NaN));
var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
...@@ -767,6 +760,10 @@ function ResetDateCache() { ...@@ -767,6 +760,10 @@ function ResetDateCache() {
function SetUpDate() { function SetUpDate() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
%SetCode($Date, DateConstructor);
%FunctionSetPrototype($Date, new $Date($NaN));
// Set up non-enumerable properties of the Date object itself. // Set up non-enumerable properties of the Date object itself.
InstallFunctions($Date, DONT_ENUM, $Array( InstallFunctions($Date, DONT_ENUM, $Array(
"UTC", DateUTC, "UTC", DateUTC,
......
...@@ -25,8 +25,15 @@ ...@@ -25,8 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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 $Array = global.Array;
// var $String = global.String;
var $JSON = global.JSON; var $JSON = global.JSON;
// -------------------------------------------------------------------
function Revive(holder, name, reviver) { function Revive(holder, name, reviver) {
var val = holder[name]; var val = holder[name];
if (IS_OBJECT(val)) { if (IS_OBJECT(val)) {
...@@ -207,14 +214,23 @@ function JSONStringify(value, replacer, space) { ...@@ -207,14 +214,23 @@ function JSONStringify(value, replacer, space) {
} }
// -------------------------------------------------------------------
function SetUpJSON() { function SetUpJSON() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set up non-enumerable properties of the JSON object.
InstallFunctions($JSON, DONT_ENUM, $Array( InstallFunctions($JSON, DONT_ENUM, $Array(
"parse", JSONParse, "parse", JSONParse,
"stringify", JSONStringify "stringify", JSONStringify
)); ));
} }
SetUpJSON();
// -------------------------------------------------------------------
// JSON Builtins
function JSONSerializeAdapter(key, object) { function JSONSerializeAdapter(key, object) {
var holder = {}; var holder = {};
...@@ -222,5 +238,3 @@ function JSONSerializeAdapter(key, object) { ...@@ -222,5 +238,3 @@ function JSONSerializeAdapter(key, object) {
// No need to pass the actual holder since there is no replacer function. // No need to pass the actual holder since there is no replacer function.
return JSONSerialize(key, holder, void 0, new InternalArray(), "", ""); return JSONSerialize(key, holder, void 0, new InternalArray(), "", "");
} }
SetUpJSON();
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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;
// Keep reference to original values of some global properties. This // Keep reference to original values of some global properties. This
// has the added benefit that the code in this file is isolated from // has the added benefit that the code in this file is isolated from
...@@ -35,10 +38,9 @@ var $abs = MathAbs; ...@@ -35,10 +38,9 @@ var $abs = MathAbs;
// Instance class name can only be set on functions. That is the only // Instance class name can only be set on functions. That is the only
// purpose for MathConstructor. // purpose for MathConstructor.
function MathConstructor() {} function MathConstructor() {}
%FunctionSetInstanceClassName(MathConstructor, 'Math');
var $Math = new MathConstructor(); var $Math = new MathConstructor();
%SetPrototype($Math, $Object.prototype);
%SetProperty(global, "Math", $Math, DONT_ENUM); // -------------------------------------------------------------------
// ECMA 262 - 15.8.2.1 // ECMA 262 - 15.8.2.1
function MathAbs(x) { function MathAbs(x) {
...@@ -216,6 +218,11 @@ function MathTan(x) { ...@@ -216,6 +218,11 @@ function MathTan(x) {
function SetUpMath() { function SetUpMath() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
%SetPrototype($Math, $Object.prototype);
%SetProperty(global, "Math", $Math, DONT_ENUM);
%FunctionSetInstanceClassName(MathConstructor, 'Math');
// Set up math constants. // Set up math constants.
// ECMA-262, section 15.8.1.1. // ECMA-262, section 15.8.1.1.
%OptimizeObjectForAddingMultipleProperties($Math, 8); %OptimizeObjectForAddingMultipleProperties($Math, 8);
......
...@@ -27,9 +27,13 @@ ...@@ -27,9 +27,13 @@
"use strict"; "use strict";
global.Proxy = new $Object(); // This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Object = global.Object;
var $Proxy = global.Proxy var $Proxy = new $Object();
// -------------------------------------------------------------------
function ProxyCreate(handler, proto) { function ProxyCreate(handler, proto) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
...@@ -62,16 +66,26 @@ function ProxyCreateFunction(handler, callTrap, constructTrap) { ...@@ -62,16 +66,26 @@ function ProxyCreateFunction(handler, callTrap, constructTrap) {
handler, callTrap, constructTrap, $Function.prototype) handler, callTrap, constructTrap, $Function.prototype)
} }
%CheckIsBootstrapping()
InstallFunctions($Proxy, DONT_ENUM, [ // -------------------------------------------------------------------
"create", ProxyCreate,
"createFunction", ProxyCreateFunction function SetUpProxy() {
]) %CheckIsBootstrapping()
global.Proxy = $Proxy;
// Set up non-enumerable properties of the Proxy object.
InstallFunctions($Proxy, DONT_ENUM, [
"create", ProxyCreate,
"createFunction", ProxyCreateFunction
])
}
SetUpProxy();
//////////////////////////////////////////////////////////////////////////////// // -------------------------------------------------------------------
// Builtins // Proxy Builtins
////////////////////////////////////////////////////////////////////////////////
function DerivedConstructTrap(callTrap) { function DerivedConstructTrap(callTrap) {
return function() { return function() {
......
...@@ -25,11 +25,15 @@ ...@@ -25,11 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Expect $Object = global.Object; // This file relies on the fact that the following declaration has been made
// Expect $Array = global.Array; // in runtime.js:
// var $Object = global.Object;
// var $Array = global.Array;
var $RegExp = global.RegExp; var $RegExp = global.RegExp;
// -------------------------------------------------------------------
// A recursive descent parser for Patterns according to the grammar of // A recursive descent parser for Patterns according to the grammar of
// ECMA-262 15.10.1, with deviations noted below. // ECMA-262 15.10.1, with deviations noted below.
function DoConstructRegExp(object, pattern, flags) { function DoConstructRegExp(object, pattern, flags) {
......
...@@ -25,24 +25,22 @@ ...@@ -25,24 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file relies on the fact that the following declaration has been made // This file relies on the fact that the following declaration has been made
// in runtime.js: // in runtime.js:
// var $String = global.String; // var $String = global.String;
// var $NaN = 0/0; // var $NaN = 0/0;
// -------------------------------------------------------------------
// Set the String function and constructor. function StringConstructor(x) {
%SetCode($String, function(x) {
var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x);
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%_SetValueOf(this, value); %_SetValueOf(this, value);
} else { } else {
return value; return value;
} }
}); }
%FunctionSetPrototype($String, new $String());
// ECMA-262 section 15.5.4.2 // ECMA-262 section 15.5.4.2
function StringToString() { function StringToString() {
...@@ -994,16 +992,19 @@ SetUpLockedPrototype(ReplaceResultBuilder, ...@@ -994,16 +992,19 @@ SetUpLockedPrototype(ReplaceResultBuilder,
function SetUpString() { function SetUpString() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set the String function and constructor.
%SetCode($String, StringConstructor);
%FunctionSetPrototype($String, new $String());
// Set up the constructor property on the String prototype object. // Set up the constructor property on the String prototype object.
%SetProperty($String.prototype, "constructor", $String, DONT_ENUM); %SetProperty($String.prototype, "constructor", $String, DONT_ENUM);
// Set up the non-enumerable functions on the String object. // Set up the non-enumerable functions on the String object.
InstallFunctions($String, DONT_ENUM, $Array( InstallFunctions($String, DONT_ENUM, $Array(
"fromCharCode", StringFromCharCode "fromCharCode", StringFromCharCode
)); ));
// Set up the non-enumerable functions on the String prototype object. // Set up the non-enumerable functions on the String prototype object.
InstallFunctions($String.prototype, DONT_ENUM, $Array( InstallFunctions($String.prototype, DONT_ENUM, $Array(
"valueOf", StringValueOf, "valueOf", StringValueOf,
......
...@@ -27,8 +27,14 @@ ...@@ -27,8 +27,14 @@
"use strict"; "use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
var $Symbol = global.Symbol; var $Symbol = global.Symbol;
// -------------------------------------------------------------------
function SymbolConstructor(x) { function SymbolConstructor(x) {
var value = var value =
IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
......
...@@ -27,8 +27,14 @@ ...@@ -27,8 +27,14 @@
"use strict"; "use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
var $ArrayBuffer = global.__ArrayBuffer; var $ArrayBuffer = global.__ArrayBuffer;
// -------------------------------------------------------------------
function ArrayBufferConstructor(byteLength) { // length = 1 function ArrayBufferConstructor(byteLength) { // length = 1
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
var l = TO_POSITIVE_INTEGER(byteLength); var l = TO_POSITIVE_INTEGER(byteLength);
...@@ -77,10 +83,9 @@ function ArrayBufferSlice(start, end) { ...@@ -77,10 +83,9 @@ function ArrayBufferSlice(start, end) {
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
(function () { function SetUpArrayBuffer() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set up the Uint16Array constructor function. // Set up the Uint16Array constructor function.
...@@ -94,5 +99,6 @@ function ArrayBufferSlice(start, end) { ...@@ -94,5 +99,6 @@ function ArrayBufferSlice(start, end) {
InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array( InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array(
"slice", ArrayBufferSlice "slice", ArrayBufferSlice
)); ));
}
})(); SetUpArrayBuffer();
...@@ -25,11 +25,15 @@ ...@@ -25,11 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
// -------------------------------------------------------------------
// This file contains support for URI manipulations written in // This file contains support for URI manipulations written in
// JavaScript. // JavaScript.
// Expect $String = global.String;
// Lazily initialized. // Lazily initialized.
var hexCharArray = 0; var hexCharArray = 0;
var hexCharCodeArray = 0; var hexCharCodeArray = 0;
...@@ -437,6 +441,7 @@ function URIUnescape(str) { ...@@ -437,6 +441,7 @@ function URIUnescape(str) {
function SetUpUri() { function SetUpUri() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// Set up non-enumerable URI functions on the global object and set // Set up non-enumerable URI functions on the global object and set
// their names. // their names.
InstallFunctions(global, DONT_ENUM, $Array( InstallFunctions(global, DONT_ENUM, $Array(
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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 // This file relies on the fact that the following declarations have been made
//
// in runtime.js: // in runtime.js:
// var $Object = global.Object; // var $Object = global.Object;
// var $Boolean = global.Boolean; // var $Boolean = global.Boolean;
...@@ -43,7 +42,6 @@ var $isFinite = GlobalIsFinite; ...@@ -43,7 +42,6 @@ var $isFinite = GlobalIsFinite;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Helper function used to install functions on objects. // Helper function used to install functions on objects.
function InstallFunctions(object, attributes, functions) { function InstallFunctions(object, attributes, functions) {
if (functions.length >= 8) { if (functions.length >= 8) {
...@@ -198,6 +196,7 @@ function GlobalEval(x) { ...@@ -198,6 +196,7 @@ function GlobalEval(x) {
// Set up global object. // Set up global object.
function SetUpGlobal() { function SetUpGlobal() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// ECMA 262 - 15.1.1.1. // ECMA 262 - 15.1.1.1.
%SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY);
...@@ -220,27 +219,10 @@ function SetUpGlobal() { ...@@ -220,27 +219,10 @@ function SetUpGlobal() {
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
$Object.prototype.constructor = $Object;
// ECMA-262 - 15.2.4.2 // ECMA-262 - 15.2.4.2
function ObjectToString() { function ObjectToString() {
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
...@@ -1357,7 +1339,7 @@ function ObjectPoisonProto(obj) { ...@@ -1357,7 +1339,7 @@ function ObjectPoisonProto(obj) {
} }
%SetCode($Object, function(x) { function ObjectConstructor(x) {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
if (x == null) return this; if (x == null) return this;
return ToObject(x); return ToObject(x);
...@@ -1365,7 +1347,7 @@ function ObjectPoisonProto(obj) { ...@@ -1365,7 +1347,7 @@ function ObjectPoisonProto(obj) {
if (x == null) return { }; if (x == null) return { };
return ToObject(x); return ToObject(x);
} }
}); }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -1374,6 +1356,8 @@ function ObjectPoisonProto(obj) { ...@@ -1374,6 +1356,8 @@ function ObjectPoisonProto(obj) {
function SetUpObject() { function SetUpObject() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
$Object.prototype.constructor = $Object;
%SetCode($Object, ObjectConstructor);
%FunctionSetName(ObjectPoisonProto, "__proto__"); %FunctionSetName(ObjectPoisonProto, "__proto__");
%FunctionRemovePrototype(ObjectPoisonProto); %FunctionRemovePrototype(ObjectPoisonProto);
%SetExpectedNumberOfProperties($Object, 4); %SetExpectedNumberOfProperties($Object, 4);
...@@ -1415,9 +1399,19 @@ function SetUpObject() { ...@@ -1415,9 +1399,19 @@ function SetUpObject() {
SetUpObject(); SetUpObject();
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Boolean // Boolean
function BooleanConstructor(x) {
if (%_IsConstructCall()) {
%_SetValueOf(this, ToBoolean(x));
} else {
return ToBoolean(x);
}
}
function BooleanToString() { function BooleanToString() {
// NOTE: Both Boolean objects and values can enter here as // NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262. // 'this'. This is not as dictated by ECMA-262.
...@@ -1444,9 +1438,13 @@ function BooleanValueOf() { ...@@ -1444,9 +1438,13 @@ function BooleanValueOf() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function SetUpBoolean () { function SetUpBoolean () {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
%SetCode($Boolean, BooleanConstructor);
%FunctionSetPrototype($Boolean, new $Boolean(false));
%SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
"toString", BooleanToString, "toString", BooleanToString,
"valueOf", BooleanValueOf "valueOf", BooleanValueOf
...@@ -1459,17 +1457,15 @@ SetUpBoolean(); ...@@ -1459,17 +1457,15 @@ SetUpBoolean();
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Number // Number
// Set the Number function and constructor. function NumberConstructor(x) {
%SetCode($Number, function(x) {
var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x);
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%_SetValueOf(this, value); %_SetValueOf(this, value);
} else { } else {
return value; return value;
} }
}); }
%FunctionSetPrototype($Number, new $Number(0));
// ECMA-262 section 15.7.4.2. // ECMA-262 section 15.7.4.2.
function NumberToString(radix) { function NumberToString(radix) {
...@@ -1607,6 +1603,10 @@ function NumberIsNaN(number) { ...@@ -1607,6 +1603,10 @@ function NumberIsNaN(number) {
function SetUpNumber() { function SetUpNumber() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
%SetCode($Number, NumberConstructor);
%FunctionSetPrototype($Number, new $Number(0));
%OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
// Set up the constructor property on the Number prototype object. // Set up the constructor property on the Number prototype object.
%SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
...@@ -1659,8 +1659,6 @@ SetUpNumber(); ...@@ -1659,8 +1659,6 @@ SetUpNumber();
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Function // Function
$Function.prototype.constructor = $Function;
function FunctionSourceString(func) { function FunctionSourceString(func) {
while (%IsJSFunctionProxy(func)) { while (%IsJSFunctionProxy(func)) {
func = %GetCallTrap(func); func = %GetCallTrap(func);
...@@ -1784,12 +1782,15 @@ function NewFunction(arg1) { // length == 1 ...@@ -1784,12 +1782,15 @@ function NewFunction(arg1) { // length == 1
return %SetNewFunctionAttributes(f); return %SetNewFunctionAttributes(f);
} }
%SetCode($Function, NewFunction);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function SetUpFunction() { function SetUpFunction() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
$Function.prototype.constructor = $Function;
%SetCode($Function, NewFunction);
InstallFunctions($Function.prototype, DONT_ENUM, $Array( InstallFunctions($Function.prototype, DONT_ENUM, $Array(
"bind", FunctionBind, "bind", FunctionBind,
"toString", FunctionToString "toString", FunctionToString
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment