Fix the types of builtin prototype objects (#3922)
ES2015 spec made an incompatible change, many builtin prototypes became no longer valid instances of their respective classes. But unfortunately it broke the web, so ES2016 reverted String, Boolean and Number prototype to the original behaviour (ES5.1). JerryScript should match the latest spec. references: - ES11 19.3.3 Properties of the Boolean Prototype Object - ES11 20.1.3 Properties of the Number Prototype Object - ES11 21.1.3 Properties of the String Prototype Object JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
This commit is contained in:
committed by
GitHub
parent
8ccccd9705
commit
281635cb40
@@ -446,7 +446,6 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
#if !ENABLED (JERRY_ESNEXT)
|
||||
#if ENABLED (JERRY_BUILTIN_STRING)
|
||||
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
|
||||
{
|
||||
@@ -483,6 +482,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
#if !ENABLED (JERRY_ESNEXT)
|
||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||
case ECMA_BUILTIN_ID_DATE_PROTOTYPE:
|
||||
{
|
||||
|
||||
@@ -47,33 +47,6 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ARRAY,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
# if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String.prototype object (21.1.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
string_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (19.3.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (20.1.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_DATE)
|
||||
/* The Date.prototype object (20.3.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
@@ -92,33 +65,6 @@ BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
regexp_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
# if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String.prototype object (15.5.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
string_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (15.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (15.7.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_DATE)
|
||||
/* The Date.prototype object (15.9.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
@@ -139,6 +85,13 @@ BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String.prototype object (15.5.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
string_prototype)
|
||||
|
||||
/* The String object (15.5.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_STRING,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -148,6 +101,13 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_STRING,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (15.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
|
||||
/* The Boolean object (15.6.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BOOLEAN,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -157,6 +117,13 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BOOLEAN,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (15.7.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
|
||||
/* The Number object (15.7.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_NUMBER,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
|
||||
@@ -2648,9 +2648,6 @@ ecma_object_check_class_name_is_object (ecma_object_t *obj_p) /**< object */
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ERROR_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_STRING_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_NUMBER_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_DATE_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)
|
||||
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
assert (Object.prototype.toString.call (String.prototype) === '[object String]');
|
||||
assert (String.prototype.toString() === "");
|
||||
|
||||
assert (Object.prototype.toString.call (Boolean.prototype) === '[object Boolean]');
|
||||
assert (Boolean.prototype.valueOf() === false);
|
||||
|
||||
assert (Object.prototype.toString.call (Number.prototype) === '[object Number]');
|
||||
assert (Number.prototype.valueOf() === 0);
|
||||
@@ -14,9 +14,6 @@
|
||||
*/
|
||||
|
||||
var prototypes = [
|
||||
String.prototype,
|
||||
Boolean.prototype,
|
||||
Number.prototype,
|
||||
Date.prototype,
|
||||
RegExp.prototype,
|
||||
Error.prototype,
|
||||
@@ -32,27 +29,6 @@ for (proto of prototypes) {
|
||||
assert (Object.prototype.toString.call (proto) === '[object Object]');
|
||||
}
|
||||
|
||||
try {
|
||||
String.prototype.toString();
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
Boolean.prototype.valueOf();
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
Number.prototype.valueOf();
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
Date.prototype.valueOf();
|
||||
assert (false);
|
||||
|
||||
@@ -13,15 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
assert (Object.prototype.toString.call (String.prototype) === '[object String]');
|
||||
assert (String.prototype.toString() === "");
|
||||
|
||||
assert (Object.prototype.toString.call (Boolean.prototype) === '[object Boolean]');
|
||||
assert (Boolean.prototype.valueOf() === false);
|
||||
|
||||
assert (Object.prototype.toString.call (Number.prototype) === '[object Number]');
|
||||
assert (Number.prototype.valueOf() === 0);
|
||||
|
||||
assert (Object.prototype.toString.call (Date.prototype) === '[object Date]');
|
||||
assert (isNaN(Date.prototype.valueOf()));
|
||||
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
<test id="built-ins/Array/prototype/splice/S15.4.4.12_A3_T1.js"><reason></reason></test>
|
||||
<test id="built-ins/Array/prototype/toLocaleString/primitive_this_value_getter.js"><reason></reason></test>
|
||||
<test id="built-ins/Array/prototype/toLocaleString/primitive_this_value.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/S15.6.3.1_A1.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/S15.6.4_A1.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/toString/S15.6.4.2_A1_T1.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/toString/S15.6.4.2_A1_T2.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/valueOf/S15.6.4.3_A1_T1.js"><reason></reason></test>
|
||||
<test id="built-ins/Boolean/prototype/valueOf/S15.6.4.3_A1_T2.js"><reason></reason></test>
|
||||
<test id="built-ins/Date/construct_with_date.js"><reason></reason></test>
|
||||
<test id="built-ins/Date/prototype/Symbol.toPrimitive/hint-invalid.js"><reason></reason></test>
|
||||
<test id="built-ins/decodeURIComponent/S15.1.3.2_A2.5_T1.js"><reason></reason></test>
|
||||
@@ -44,51 +38,6 @@
|
||||
<test id="built-ins/GeneratorFunction/instance-restricted-properties.js"><reason></reason></test>
|
||||
<test id="built-ins/GeneratorPrototype/next/context-constructor-invocation.js"><reason></reason></test>
|
||||
<test id="built-ins/Map/prototype/Symbol.iterator.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/15.7.4-1.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/S15.7.3.1_A2_T1.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/S15.7.3.1_A2_T2.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/S15.7.3.1_A3.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/S15.7.4_A1.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toFixed/S15.7.4.5_A1.1_T01.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A1_T01.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A1_T02.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A1_T03.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T01.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T02.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T03.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T04.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T05.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T06.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T07.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T08.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T09.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T10.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T11.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T12.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T13.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T14.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T15.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T16.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T17.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T18.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T19.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T20.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T21.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T22.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T23.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T24.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T25.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T26.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T27.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T28.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T29.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T30.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T31.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T32.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T33.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/toString/S15.7.4.2_A2_T34.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T01.js"><reason></reason></test>
|
||||
<test id="built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T02.js"><reason></reason></test>
|
||||
<test id="built-ins/Object/prototype/hasOwnProperty/symbol_property_toPrimitive.js"><reason></reason></test>
|
||||
<test id="built-ins/Object/prototype/hasOwnProperty/symbol_property_toString.js"><reason></reason></test>
|
||||
<test id="built-ins/Object/prototype/hasOwnProperty/symbol_property_valueOf.js"><reason></reason></test>
|
||||
@@ -151,9 +100,6 @@
|
||||
<test id="built-ins/String/prototype/normalize/return-normalized-string-from-coerced-form.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/normalize/return-normalized-string.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/normalize/return-normalized-string-using-default-parameter.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/S15.5.4_A1.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/S15.5.4_A2.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/S15.5.4_A3.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/split/S15.5.4.14_A2_T37.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/toLocaleLowerCase/special_casing_conditional.js"><reason></reason></test>
|
||||
<test id="built-ins/String/prototype/toLocaleLowerCase/supplementary_plane.js"><reason></reason></test>
|
||||
|
||||
Reference in New Issue
Block a user