From 391f799152b3c36e74998bae4dae66526313b17e Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sun, 7 Jun 2020 18:50:00 +0200 Subject: [PATCH] =?UTF-8?q?Add=C2=A0tests=20for=C2=A0cross=E2=80=91realm?= =?UTF-8?q?=20and=C2=A0subclass=20`RegExp.prototype.compile`=C2=A0calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compile/this-cross-realm-instance.js | 34 +++++++++++++++++++ .../compile/this-subclass-instance.js | 25 ++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js create mode 100644 test/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js diff --git a/test/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js b/test/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js new file mode 100644 index 0000000000..cab609967f --- /dev/null +++ b/test/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js @@ -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`" +); diff --git a/test/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js b/test/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js new file mode 100644 index 0000000000..ea44faa4b1 --- /dev/null +++ b/test/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js @@ -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" +);