Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[ES6] Use @isObject to check Object Type instead of using instanceof
https://bugs.webkit.org/show_bug.cgi?id=156676 Reviewed by Darin Adler. Use @isObject instead of `instanceof @Object`. The `instanceof` check is not enough to check Object Type. For example, given 2 realms, the object created in one realm does not inherit the Object of another realm. Another example is that the object which does not inherit Object. This object can be easily created by calling `Object.create(null)`. * builtins/RegExpPrototype.js: (match): * jsc.cpp: (GlobalObject::finishCreation): (functionCreateGlobalObject): * tests/stress/regexp-match-in-other-realm-should-work.js: Added. (shouldBe): * tests/stress/regexp-match-should-work-with-objects-not-inheriting-object-prototype.js: Added. (shouldBe): (regexp.exec): Canonical link: https://commits.webkit.org/174782@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199647 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
54 additions
and 1 deletion.
- +24 −0 Source/JavaScriptCore/ChangeLog
- +1 −1 Source/JavaScriptCore/builtins/RegExpPrototype.js
- +8 −0 Source/JavaScriptCore/jsc.cpp
- +10 −0 Source/JavaScriptCore/tests/stress/regexp-match-in-other-realm-should-work.js
- +11 −0 ...aScriptCore/tests/stress/regexp-match-should-work-with-objects-not-inheriting-object-prototype.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -47,7 +47,7 @@ function match(str) | ||
{ | ||
"use strict"; | ||
|
||
if (!@isObject(this)) | ||
throw new @TypeError("RegExp.prototype.@@match requires that |this| be an Object"); | ||
|
||
let regexp = @Object(this); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,10 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`bad value: ${String(actual)}`); | ||
} | ||
|
||
var regexp = /Hello/; | ||
var string = "Hello"; | ||
var otherRealm = createGlobalObject(); | ||
shouldBe(otherRealm.RegExp.prototype[Symbol.match].call(regexp, string)[0], string) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,11 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`bad value: ${String(actual)}`); | ||
} | ||
var regexp = Object.create(null); | ||
regexp.reg = /Hello/; | ||
regexp.exec = function (value) { | ||
return regexp.reg.exec(value); | ||
}; | ||
var string = "Hello"; | ||
shouldBe(RegExp.prototype[Symbol.match].call(regexp, string)[0], string) |