[intl] Implement ECMA402 PR500 Use OrdinaryHasInstance
Implement https://github.com/tc39/ecma402/pull/500 For the legacy [optional] Unwrap*Format steps, use OrdinaryHasInstance instead of InstanceofOperator. ECMA402 agree w/ PR500 on 2021-1-14 Bug: v8:10981 Change-Id: Ic697aa245b11fecaf998127c009e59a821aaa01e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2444092 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Shu-yu Guo <syg@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#72303}
This commit is contained in:
parent
89ea6caf56
commit
c2795bd790
@ -280,16 +280,14 @@ Object LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate,
|
||||
// 4. Let this be the this value.
|
||||
if (args.new_target()->IsUndefined(isolate)) {
|
||||
Handle<Object> receiver = args.receiver();
|
||||
|
||||
// 5. If NewTarget is undefined and ? InstanceofOperator(this, %<T>%)
|
||||
// 5. If NewTarget is undefined and ? OrdinaryHasInstance(%<T>%, this)
|
||||
// is true, then Look up the intrinsic value that has been stored on
|
||||
// the context.
|
||||
Handle<Object> is_instance_of_obj;
|
||||
Handle<Object> ordinary_has_instance_obj;
|
||||
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
||||
isolate, is_instance_of_obj,
|
||||
Object::InstanceOf(isolate, receiver, constructor));
|
||||
|
||||
if (is_instance_of_obj->BooleanValue(isolate)) {
|
||||
isolate, ordinary_has_instance_obj,
|
||||
Object::OrdinaryHasInstance(isolate, constructor, receiver));
|
||||
if (ordinary_has_instance_obj->BooleanValue(isolate)) {
|
||||
if (!receiver->IsJSReceiver()) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate,
|
||||
|
@ -617,15 +617,15 @@ MaybeHandle<Object> Intl::LegacyUnwrapReceiver(Isolate* isolate,
|
||||
Handle<JSReceiver> receiver,
|
||||
Handle<JSFunction> constructor,
|
||||
bool has_initialized_slot) {
|
||||
Handle<Object> obj_is_instance_of;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, obj_is_instance_of,
|
||||
Object::InstanceOf(isolate, receiver, constructor),
|
||||
Object);
|
||||
bool is_instance_of = obj_is_instance_of->BooleanValue(isolate);
|
||||
Handle<Object> obj_ordinary_has_instance;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, obj_ordinary_has_instance,
|
||||
Object::OrdinaryHasInstance(isolate, constructor, receiver), Object);
|
||||
bool ordinary_has_instance = obj_ordinary_has_instance->BooleanValue(isolate);
|
||||
|
||||
// 2. If receiver does not have an [[Initialized...]] internal slot
|
||||
// and ? InstanceofOperator(receiver, constructor) is true, then
|
||||
if (!has_initialized_slot && is_instance_of) {
|
||||
// and ? OrdinaryHasInstance(constructor, receiver) is true, then
|
||||
if (!has_initialized_slot && ordinary_has_instance) {
|
||||
// 2. a. Let new_receiver be ? Get(receiver, %Intl%.[[FallbackSymbol]]).
|
||||
Handle<Object> new_receiver;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2020 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Verify ECMA402 PR 500 Use OrdinaryHasInstance in normative optional steps
|
||||
// https://github.com/tc39/ecma402/pull/500
|
||||
|
||||
Object.defineProperty(Intl.DateTimeFormat, Symbol.hasInstance, {
|
||||
get() { throw new Error("Intl.DateTimeFormat[@@hasInstance] lookup"); }
|
||||
});
|
||||
|
||||
var dtf;
|
||||
assertDoesNotThrow(() => dtf = new Intl.DateTimeFormat());
|
||||
assertDoesNotThrow(() => dtf.format(new Date()));
|
||||
assertDoesNotThrow(() => dtf.resolvedOptions());
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2020 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Verify ECMA402 PR 500 Use OrdinaryHasInstance in normative optional steps
|
||||
// https://github.com/tc39/ecma402/pull/500
|
||||
|
||||
Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, {
|
||||
get() { throw new Error("Intl.NumberFormat[@@hasInstance] lookup"); }
|
||||
});
|
||||
|
||||
var nf;
|
||||
assertDoesNotThrow(() => nf = new Intl.NumberFormat());
|
||||
assertDoesNotThrow(() => nf.format(123));
|
||||
assertDoesNotThrow(() => nf.resolvedOptions());
|
@ -5,8 +5,6 @@
|
||||
// Make sure passing 1 or false to patched construtor won't cause crash
|
||||
|
||||
Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, { value: _ => true });
|
||||
assertThrows(() =>
|
||||
Intl.NumberFormat.call(1), TypeError);
|
||||
assertDoesNotThrow(() => Intl.NumberFormat.call(1));
|
||||
|
||||
assertThrows(() =>
|
||||
Intl.NumberFormat.call(false), TypeError);
|
||||
assertDoesNotThrow(() => Intl.NumberFormat.call(false));
|
||||
|
Loading…
Reference in New Issue
Block a user