From 76ab0187c0ec58fe07453b91a83913bf28bd544d Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Tue, 16 Feb 2021 17:15:04 +0530 Subject: [PATCH] Add NumberFormat tests for OrdinaryHasInstance Add tests to make sure NumberFormat does not call the instanceof operator and calls OrdinaryHasInstance instead. Refs: https://github.com/tc39/ecma402/pull/500 --- .../NumberFormat/constructor-no-instanceof.js | 16 ++++++++++++++++ .../prototype/format/no-instanceof.js | 18 ++++++++++++++++++ .../prototype/resolvedOptions/no-instanceof.js | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 test/intl402/NumberFormat/constructor-no-instanceof.js create mode 100644 test/intl402/NumberFormat/prototype/format/no-instanceof.js create mode 100644 test/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js diff --git a/test/intl402/NumberFormat/constructor-no-instanceof.js b/test/intl402/NumberFormat/constructor-no-instanceof.js new file mode 100644 index 0000000000..259c37ef66 --- /dev/null +++ b/test/intl402/NumberFormat/constructor-no-instanceof.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.resolvedOptions +description: > + Tests that Intl.NumberFormat.prototype.resolvedOptions calls + OrdinaryHasInstance instead of the instanceof operator which includes a + Symbol.hasInstance lookup and call among other things. +---*/ + +Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, { + get() { throw new Test262Error(); } +}); + +Intl.NumberFormat(); diff --git a/test/intl402/NumberFormat/prototype/format/no-instanceof.js b/test/intl402/NumberFormat/prototype/format/no-instanceof.js new file mode 100644 index 0000000000..ddeed1435f --- /dev/null +++ b/test/intl402/NumberFormat/prototype/format/no-instanceof.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.resolvedOptions +description: > + Tests that Intl.NumberFormat.prototype.resolvedOptions calls + OrdinaryHasInstance instead of the instanceof operator which includes a + Symbol.hasInstance lookup and call among other things. +---*/ + +const nf = new Intl.NumberFormat(); + +Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, { + get() { throw new Test262Error(); } +}); + +nf.format; diff --git a/test/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js b/test/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js new file mode 100644 index 0000000000..55fd6fd833 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.NumberFormat.prototype.resolvedOptions +description: > + Tests that Intl.NumberFormat.prototype.resolvedOptions calls + OrdinaryHasInstance instead of the instanceof operator which includes a + Symbol.hasInstance lookup and call among other things. +---*/ + +const nf = new Intl.NumberFormat(); + +Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, { + get() { throw new Test262Error(); } +}); + +nf.resolvedOptions();