Add tests for cross‑realm and subclass `RegExp.prototype.compile` calls

This commit is contained in:
ExE Boss 2020-06-07 18:50:00 +02:00 committed by Rick Waldron
parent d06c21c03a
commit 391f799152
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,34 @@
// Copyright (C) 2020 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-regexp.prototype.compile
description: RegExp.prototype.compile throws a TypeError for cross-realm calls
features: [legacy-regexp,cross-realm]
---*/
const other = $262.createRealm().global;
const regexp = new RegExp("");
const otherRealm_regexp = new other.RegExp("");
assert.throws(
TypeError,
function () {
RegExp.prototype.compile.call(otherRealm_regexp);
},
"`RegExp.prototype.compile.call(otherRealm_regexp)` throws TypeError"
);
assert.throws(
TypeError,
function () {
other.RegExp.prototype.compile.call(regexp);
},
"`other.RegExp.prototype.compile.call(regexp)` throws TypeError"
);
assert.sameValue(
otherRealm_regexp.compile(),
otherRealm_regexp,
"`otherRealm_regexp.compile()` is SameValue with `otherRealm_regexp`"
);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2020 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-regexp.prototype.compile
description: RegExp.prototype.compile throws a TypeError for calls on subclasses
features: [legacy-regexp,class]
---*/
const subclass_regexp = new (class extends RegExp {})("");
assert.throws(
TypeError,
function () {
subclass_regexp.compile();
},
"`subclass_regexp.compile()` throws TypeError"
);
assert.throws(
TypeError,
function () {
RegExp.prototype.compile.call(subclass_regexp);
},
"`RegExp.prototype.compile.call(subclass_regexp)` throws TypeError"
);