Commit b1578a15 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Use new.target in favor of %_IsConstructCall intrinsic (1).

This switches several builtin methods to use the ES6 new.target value
when determined whether being called as a constructor or not. This is
prepatory work for fully deprecating the aforementioned intrinsic.

R=rossberg@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#32397}
parent 026095a3
...@@ -125,7 +125,7 @@ function GetHash(key) { ...@@ -125,7 +125,7 @@ function GetHash(key) {
// Harmony Set // Harmony Set
function SetConstructor(iterable) { function SetConstructor(iterable) {
if (!%_IsConstructCall()) { if (IS_UNDEFINED(new.target)) {
throw MakeTypeError(kConstructorNotFunction, "Set"); throw MakeTypeError(kConstructorNotFunction, "Set");
} }
...@@ -281,7 +281,7 @@ utils.InstallFunctions(GlobalSet.prototype, DONT_ENUM, [ ...@@ -281,7 +281,7 @@ utils.InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
// Harmony Map // Harmony Map
function MapConstructor(iterable) { function MapConstructor(iterable) {
if (!%_IsConstructCall()) { if (IS_UNDEFINED(new.target)) {
throw MakeTypeError(kConstructorNotFunction, "Map"); throw MakeTypeError(kConstructorNotFunction, "Map");
} }
......
...@@ -22,7 +22,7 @@ utils.Import(function(from) { ...@@ -22,7 +22,7 @@ utils.Import(function(from) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SharedArrayBufferConstructor(length) { // length = 1 function SharedArrayBufferConstructor(length) { // length = 1
if (%_IsConstructCall()) { if (!IS_UNDEFINED(new.target)) {
var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength); var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength);
%ArrayBufferInitialize(this, byteLength, kShared); %ArrayBufferInitialize(this, byteLength, kShared);
} else { } else {
......
...@@ -433,34 +433,44 @@ SIMD_X16_TYPES(DECLARE_X16_FUNCTIONS) ...@@ -433,34 +433,44 @@ SIMD_X16_TYPES(DECLARE_X16_FUNCTIONS)
//------------------------------------------------------------------- //-------------------------------------------------------------------
function Float32x4Constructor(c0, c1, c2, c3) { function Float32x4Constructor(c0, c1, c2, c3) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Float32x4"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Float32x4");
}
return %CreateFloat32x4(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateFloat32x4(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3)); TO_NUMBER(c2), TO_NUMBER(c3));
} }
function Int32x4Constructor(c0, c1, c2, c3) { function Int32x4Constructor(c0, c1, c2, c3) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int32x4"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Int32x4");
}
return %CreateInt32x4(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateInt32x4(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3)); TO_NUMBER(c2), TO_NUMBER(c3));
} }
function Uint32x4Constructor(c0, c1, c2, c3) { function Uint32x4Constructor(c0, c1, c2, c3) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Uint32x4"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Uint32x4");
}
return %CreateUint32x4(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateUint32x4(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3)); TO_NUMBER(c2), TO_NUMBER(c3));
} }
function Bool32x4Constructor(c0, c1, c2, c3) { function Bool32x4Constructor(c0, c1, c2, c3) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool32x4"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Bool32x4");
}
return %CreateBool32x4(c0, c1, c2, c3); return %CreateBool32x4(c0, c1, c2, c3);
} }
function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) { function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int16x8"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Int16x8");
}
return %CreateInt16x8(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateInt16x8(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3), TO_NUMBER(c2), TO_NUMBER(c3),
TO_NUMBER(c4), TO_NUMBER(c5), TO_NUMBER(c4), TO_NUMBER(c5),
...@@ -469,7 +479,9 @@ function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) { ...@@ -469,7 +479,9 @@ function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
function Uint16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) { function Uint16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Uint16x8"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Uint16x8");
}
return %CreateUint16x8(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateUint16x8(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3), TO_NUMBER(c2), TO_NUMBER(c3),
TO_NUMBER(c4), TO_NUMBER(c5), TO_NUMBER(c4), TO_NUMBER(c5),
...@@ -478,14 +490,18 @@ function Uint16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) { ...@@ -478,14 +490,18 @@ function Uint16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
function Bool16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) { function Bool16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool16x8"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Bool16x8");
}
return %CreateBool16x8(c0, c1, c2, c3, c4, c5, c6, c7); return %CreateBool16x8(c0, c1, c2, c3, c4, c5, c6, c7);
} }
function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
c12, c13, c14, c15) { c12, c13, c14, c15) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int8x16"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Int8x16");
}
return %CreateInt8x16(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateInt8x16(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3), TO_NUMBER(c2), TO_NUMBER(c3),
TO_NUMBER(c4), TO_NUMBER(c5), TO_NUMBER(c4), TO_NUMBER(c5),
...@@ -499,7 +515,9 @@ function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, ...@@ -499,7 +515,9 @@ function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
function Uint8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, function Uint8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
c12, c13, c14, c15) { c12, c13, c14, c15) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Uint8x16"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Uint8x16");
}
return %CreateUint8x16(TO_NUMBER(c0), TO_NUMBER(c1), return %CreateUint8x16(TO_NUMBER(c0), TO_NUMBER(c1),
TO_NUMBER(c2), TO_NUMBER(c3), TO_NUMBER(c2), TO_NUMBER(c3),
TO_NUMBER(c4), TO_NUMBER(c5), TO_NUMBER(c4), TO_NUMBER(c5),
...@@ -513,7 +531,9 @@ function Uint8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, ...@@ -513,7 +531,9 @@ function Uint8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
function Bool8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, function Bool8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
c12, c13, c14, c15) { c12, c13, c14, c15) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool8x16"); if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kNotConstructor, "Bool8x16");
}
return %CreateBool8x16(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, return %CreateBool8x16(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,
c13, c14, c15); c13, c14, c15);
} }
......
...@@ -937,7 +937,7 @@ function DefineError(global, f) { ...@@ -937,7 +937,7 @@ function DefineError(global, f) {
%AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM);
%AddNamedProperty(f.prototype, 'name', name, DONT_ENUM); %AddNamedProperty(f.prototype, 'name', name, DONT_ENUM);
%SetCode(f, function(m) { %SetCode(f, function(m) {
if (%_IsConstructCall()) { if (!IS_UNDEFINED(new.target)) {
try { captureStackTrace(this, f); } catch (e) { } try { captureStackTrace(this, f); } catch (e) { }
// Define all the expected properties directly on the error // Define all the expected properties directly on the error
// object. This avoids going through getters and setters defined // object. This avoids going through getters and setters defined
......
...@@ -25,7 +25,7 @@ utils.Import(function(from) { ...@@ -25,7 +25,7 @@ utils.Import(function(from) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
function ProxyCreate(target, handler) { function ProxyCreate(target, handler) {
if (!%_IsConstructCall()) { if (IS_UNDEFINED(new.target)) {
throw MakeTypeError(kConstructorNotFunction, "Proxy"); throw MakeTypeError(kConstructorNotFunction, "Proxy");
} }
return %CreateJSProxy(target, handler); return %CreateJSProxy(target, handler);
...@@ -66,7 +66,7 @@ function DerivedConstructTrap(callTrap) { ...@@ -66,7 +66,7 @@ function DerivedConstructTrap(callTrap) {
function DelegateCallAndConstruct(callTrap, constructTrap) { function DelegateCallAndConstruct(callTrap, constructTrap) {
return function() { return function() {
return %Apply(%_IsConstructCall() ? constructTrap : callTrap, return %Apply(IS_UNDEFINED(new.target) ? callTrap : constructTrap,
this, arguments, 0, %_ArgumentsLength()) this, arguments, 0, %_ArgumentsLength())
} }
} }
......
...@@ -29,7 +29,7 @@ utils.Import(function(from) { ...@@ -29,7 +29,7 @@ utils.Import(function(from) {
// Harmony WeakMap // Harmony WeakMap
function WeakMapConstructor(iterable) { function WeakMapConstructor(iterable) {
if (!%_IsConstructCall()) { if (IS_UNDEFINED(new.target)) {
throw MakeTypeError(kConstructorNotFunction, "WeakMap"); throw MakeTypeError(kConstructorNotFunction, "WeakMap");
} }
...@@ -118,7 +118,7 @@ utils.InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [ ...@@ -118,7 +118,7 @@ utils.InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [
// Harmony WeakSet // Harmony WeakSet
function WeakSetConstructor(iterable) { function WeakSetConstructor(iterable) {
if (!%_IsConstructCall()) { if (IS_UNDEFINED(new.target)) {
throw MakeTypeError(kConstructorNotFunction, "WeakSet"); throw MakeTypeError(kConstructorNotFunction, "WeakSet");
} }
......
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