Fix the types of builtin prototype objects (#3663)
In ES2015 many builtin prototypes are no longer valid instances of their respective classes. This change updates affected prototypes to be regular objects as required. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
assert (Date.length == 7);
|
||||
assert (Object.prototype.toString.call (Date.prototype) === '[object Date]');
|
||||
|
||||
var d;
|
||||
|
||||
@@ -28,8 +27,6 @@ catch (e)
|
||||
assert (e.message === "foo");
|
||||
}
|
||||
|
||||
assert (isNaN(Date.prototype.valueOf.call(Date.prototype)));
|
||||
|
||||
d = new Date("abcd");
|
||||
assert (isNaN(d.valueOf()));
|
||||
|
||||
|
||||
@@ -224,19 +224,3 @@ assert (isNaN (d.setMonth()));
|
||||
assert (isNaN (d.setUTCMonth()));
|
||||
assert (isNaN (d.setFullYear()));
|
||||
assert (isNaN (d.setUTCFullYear()));
|
||||
|
||||
assert (isNaN (Date.prototype.setTime()));
|
||||
assert (isNaN (Date.prototype.setMilliseconds()));
|
||||
assert (isNaN (Date.prototype.setUTCMilliseconds()));
|
||||
assert (isNaN (Date.prototype.setSeconds()));
|
||||
assert (isNaN (Date.prototype.setUTCSeconds()));
|
||||
assert (isNaN (Date.prototype.setMinutes()));
|
||||
assert (isNaN (Date.prototype.setUTCMinutes()));
|
||||
assert (isNaN (Date.prototype.setHours()));
|
||||
assert (isNaN (Date.prototype.setUTCHours()));
|
||||
assert (isNaN (Date.prototype.setDate()));
|
||||
assert (isNaN (Date.prototype.getUTCDate()));
|
||||
assert (isNaN (Date.prototype.setMonth()));
|
||||
assert (isNaN (Date.prototype.setUTCMonth()));
|
||||
assert (isNaN (Date.prototype.setFullYear()));
|
||||
assert (isNaN (Date.prototype.setUTCFullYear()));
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var prototypes = [
|
||||
String.prototype,
|
||||
Boolean.prototype,
|
||||
Number.prototype,
|
||||
Date.prototype,
|
||||
RegExp.prototype,
|
||||
Error.prototype,
|
||||
EvalError.prototype,
|
||||
RangeError.prototype,
|
||||
ReferenceError.prototype,
|
||||
SyntaxError.prototype,
|
||||
TypeError.prototype,
|
||||
URIError.prototype
|
||||
]
|
||||
|
||||
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);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.exec("");
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.compile("a", "u");
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.source;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.global;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.ignoreCase;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.multiline;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.sticky;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp.prototype.unicode;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
@@ -60,3 +60,13 @@ assert (r.lastIndex === 0);
|
||||
var r = /abc/yg;
|
||||
m = r.exec ("strabcstr");
|
||||
assert (m === null);
|
||||
|
||||
try {
|
||||
RegExp.prototype.flags;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
var flagsProp = Object.getOwnPropertyDescriptor (RegExp.prototype, "flags");
|
||||
assert(flagsProp.get.call({}) === '');
|
||||
|
||||
@@ -38,3 +38,18 @@ assert(new RegExp('/\n/').source.length === 6);
|
||||
|
||||
assert(new RegExp(/\/\//).source === '\\/\\/');
|
||||
assert(new RegExp(/\?\//g).source === '\\?\\/');
|
||||
|
||||
try {
|
||||
RegExp.prototype.source;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
var sourceProp = Object.getOwnPropertyDescriptor (RegExp.prototype, "source");
|
||||
try {
|
||||
sourceProp.get.call({});
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
assert(String.prototype.repeat(1.1) === "");
|
||||
assert("".repeat(1.1) === "");
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
// limitations under the License.
|
||||
|
||||
for (var [] of [[], []])
|
||||
String.prototype.split(RegExp.prototype)
|
||||
"".split(new RegExp())
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* 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);
|
||||
|
||||
assert (Object.prototype.toString.call (Date.prototype) === '[object Date]');
|
||||
assert (isNaN(Date.prototype.valueOf()));
|
||||
|
||||
assert (isNaN (Date.prototype.setTime()));
|
||||
assert (isNaN (Date.prototype.setMilliseconds()));
|
||||
assert (isNaN (Date.prototype.setUTCMilliseconds()));
|
||||
assert (isNaN (Date.prototype.setSeconds()));
|
||||
assert (isNaN (Date.prototype.setUTCSeconds()));
|
||||
assert (isNaN (Date.prototype.setMinutes()));
|
||||
assert (isNaN (Date.prototype.setUTCMinutes()));
|
||||
assert (isNaN (Date.prototype.setHours()));
|
||||
assert (isNaN (Date.prototype.setUTCHours()));
|
||||
assert (isNaN (Date.prototype.setDate()));
|
||||
assert (isNaN (Date.prototype.getUTCDate()));
|
||||
assert (isNaN (Date.prototype.setMonth()));
|
||||
assert (isNaN (Date.prototype.setUTCMonth()));
|
||||
assert (isNaN (Date.prototype.setFullYear()));
|
||||
assert (isNaN (Date.prototype.setUTCFullYear()));
|
||||
|
||||
assert (Object.prototype.toString.call (RegExp.prototype) === '[object RegExp]');
|
||||
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
RegExp.prototype.source = "a";
|
||||
RegExp.prototype.global = true;
|
||||
RegExp.prototype.ignoreCase = true;
|
||||
RegExp.prototype.multiline = true;
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
delete RegExp.prototype.source;
|
||||
delete RegExp.prototype.global;
|
||||
delete RegExp.prototype.ignoreCase;
|
||||
delete RegExp.prototype.multiline;
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
var prototypes = [
|
||||
Error.prototype,
|
||||
EvalError.prototype,
|
||||
RangeError.prototype,
|
||||
ReferenceError.prototype,
|
||||
SyntaxError.prototype,
|
||||
TypeError.prototype,
|
||||
URIError.prototype
|
||||
]
|
||||
|
||||
prototypes.forEach (function (proto) {
|
||||
assert (Object.prototype.toString.call (proto) === '[object Error]');
|
||||
})
|
||||
@@ -76,8 +76,6 @@ assert (r.global == true);
|
||||
assert (r.ignoreCase == true);
|
||||
assert (r.multiline == true);
|
||||
|
||||
assert(Object.prototype.toString.call(RegExp.prototype) === '[object RegExp]');
|
||||
|
||||
/* The 'undefined' argument for the RegExp constructor should not be converted to string,
|
||||
* and it should behave just like when there is no argument.
|
||||
*/
|
||||
@@ -130,25 +128,3 @@ assert (r.multiline == false);
|
||||
|
||||
/* RegExp properties */
|
||||
assert (RegExp.length === 2);
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
RegExp.prototype.source = "a";
|
||||
RegExp.prototype.global = true;
|
||||
RegExp.prototype.ignoreCase = true;
|
||||
RegExp.prototype.multiline = true;
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
delete RegExp.prototype.source;
|
||||
delete RegExp.prototype.global;
|
||||
delete RegExp.prototype.ignoreCase;
|
||||
delete RegExp.prototype.multiline;
|
||||
assert (RegExp.prototype.source === "(?:)");
|
||||
assert (RegExp.prototype.global === false);
|
||||
assert (RegExp.prototype.ignoreCase === false);
|
||||
assert (RegExp.prototype.multiline === false);
|
||||
|
||||
Reference in New Issue
Block a user