Skip to content

Commit 09d1472

Browse files
camillobruniCommit Bot
authored andcommitted
[intl] Fix Intl.NumberFormat constructor
Call the @@hasInstance trap only when required by the spec. Bug: chromium:1052647 Change-Id: I7a0a3133c7b6280c6a3215e379bf02e9c22ffe55 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2082560 Commit-Queue: Camillo Bruni <[email protected]> Reviewed-by: Sathya Gunasekaran <[email protected]> Cr-Commit-Position: refs/heads/master@{#66558}
1 parent f3babaf commit 09d1472

3 files changed

Lines changed: 50 additions & 40 deletions

File tree

src/builtins/builtins-intl.cc

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,11 @@ Object LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate,
265265

266266
// [[Construct]]
267267
Handle<JSFunction> target = args.target();
268-
269268
Handle<Object> locales = args.atOrUndefined(isolate, 1);
270269
Handle<Object> options = args.atOrUndefined(isolate, 2);
271270

272271
// 2. Let format be ? OrdinaryCreateFromConstructor(newTarget,
273272
// "%<T>Prototype%", ...).
274-
275273
Handle<Map> map;
276274
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
277275
isolate, map, JSFunction::GetDerivedMap(isolate, target, new_target));
@@ -281,45 +279,42 @@ Object LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate,
281279
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
282280
isolate, format, T::New(isolate, map, locales, options, method));
283281
// 4. Let this be the this value.
284-
Handle<Object> receiver = args.receiver();
285-
286-
// 5. If NewTarget is undefined and ? InstanceofOperator(this, %<T>%)
287-
// is true, then
288-
//
289-
// Look up the intrinsic value that has been stored on the context.
290-
// Call the instanceof function
291-
Handle<Object> is_instance_of_obj;
292-
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
293-
isolate, is_instance_of_obj,
294-
Object::InstanceOf(isolate, receiver, constructor));
295-
296-
// Get the boolean value of the result
297-
bool is_instance_of = is_instance_of_obj->BooleanValue(isolate);
298-
299-
if (args.new_target()->IsUndefined(isolate) && is_instance_of) {
300-
if (!receiver->IsJSReceiver()) {
301-
THROW_NEW_ERROR_RETURN_FAILURE(
302-
isolate,
303-
NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
304-
isolate->factory()->NewStringFromAsciiChecked(method),
305-
receiver));
282+
if (args.new_target()->IsUndefined(isolate)) {
283+
Handle<Object> receiver = args.receiver();
284+
285+
// 5. If NewTarget is undefined and ? InstanceofOperator(this, %<T>%)
286+
// is true, then Look up the intrinsic value that has been stored on
287+
// the context.
288+
Handle<Object> is_instance_of_obj;
289+
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
290+
isolate, is_instance_of_obj,
291+
Object::InstanceOf(isolate, receiver, constructor));
292+
293+
if (is_instance_of_obj->BooleanValue(isolate)) {
294+
if (!receiver->IsJSReceiver()) {
295+
THROW_NEW_ERROR_RETURN_FAILURE(
296+
isolate,
297+
NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
298+
isolate->factory()->NewStringFromAsciiChecked(method),
299+
receiver));
300+
}
301+
Handle<JSReceiver> rec = Handle<JSReceiver>::cast(receiver);
302+
// a. Perform ? DefinePropertyOrThrow(this,
303+
// %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: format,
304+
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
305+
PropertyDescriptor desc;
306+
desc.set_value(format);
307+
desc.set_writable(false);
308+
desc.set_enumerable(false);
309+
desc.set_configurable(false);
310+
Maybe<bool> success = JSReceiver::DefineOwnProperty(
311+
isolate, rec, isolate->factory()->intl_fallback_symbol(), &desc,
312+
Just(kThrowOnError));
313+
MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
314+
CHECK(success.FromJust());
315+
// b. b. Return this.
316+
return *receiver;
306317
}
307-
Handle<JSReceiver> rec = Handle<JSReceiver>::cast(receiver);
308-
// a. Perform ? DefinePropertyOrThrow(this,
309-
// %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: format,
310-
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
311-
PropertyDescriptor desc;
312-
desc.set_value(format);
313-
desc.set_writable(false);
314-
desc.set_enumerable(false);
315-
desc.set_configurable(false);
316-
Maybe<bool> success = JSReceiver::DefineOwnProperty(
317-
isolate, rec, isolate->factory()->intl_fallback_symbol(), &desc,
318-
Just(kThrowOnError));
319-
MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
320-
CHECK(success.FromJust());
321-
// b. b. Return this.
322-
return *receiver;
323318
}
324319
// 6. Return format.
325320
return *format;

test/mjsunit/mjsunit.status

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@
404404
'tzoffset-transition-moscow': [SKIP],
405405
'tzoffset-transition-new-york': [SKIP],
406406
'tzoffset-seoul': [SKIP],
407+
408+
# noi18n is required for Intl
409+
'regress/regress-crbug-1052647': [SKIP],
407410
}], # 'no_i18n'
408411

409412
##############################################################################
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
let useArgs = undefined;
6+
function f(arg) {
7+
useArgs = 'result' + arguments[0] + arg;
8+
}
9+
10+
Intl.NumberFormat.__proto__ = { [Symbol.hasInstance]: f };
11+
12+
new Intl.NumberFormat();

0 commit comments

Comments
 (0)