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:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user