diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc index ecdab593b2..1cf4f9f644 100644 --- a/src/runtime/runtime-classes.cc +++ b/src/runtime/runtime-classes.cc @@ -41,13 +41,20 @@ RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); Handle name(constructor->shared().Name(), isolate); + + Handle context = handle(constructor->native_context(), isolate); + DCHECK(context->IsNativeContext()); + Handle realm_type_error_function( + JSFunction::cast(context->get(Context::TYPE_ERROR_FUNCTION_INDEX)), + isolate); if (name->length() == 0) { THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError(MessageTemplate::kAnonymousConstructorNonCallable)); + isolate, NewError(realm_type_error_function, + MessageTemplate::kAnonymousConstructorNonCallable)); } THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError(MessageTemplate::kConstructorNonCallable, name)); + isolate, NewError(realm_type_error_function, + MessageTemplate::kConstructorNonCallable, name)); } diff --git a/test/mjsunit/es6/classes-constructor.js b/test/mjsunit/es6/classes-constructor.js index faf9404f07..8425725055 100644 --- a/test/mjsunit/es6/classes-constructor.js +++ b/test/mjsunit/es6/classes-constructor.js @@ -25,11 +25,12 @@ throw Error('Should not happen!'); } - // ES6 9.2.1[[Call]] throws a TypeError in the caller context/Realm when the - // called function is a classConstructor + // https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist + // 10.2.1 [[Call]] throws a TypeError created in callee context with F's + // associated Realm Record when the called function is a classConstructor assertThrows(function() { Realm.eval(realmIndex, "A()") }, otherTypeError); - assertThrows(function() { instance.constructor() }, TypeError); - assertThrows(function() { A() }, TypeError); + assertThrows(function() { instance.constructor() }, otherTypeError); + assertThrows(function() { A() }, otherTypeError); // ES6 9.3.1 call() first activates the callee context before invoking the // method. The TypeError from the constructor is thus thrown in the other diff --git a/test/test262/test262.status b/test/test262/test262.status index 8f3871c4af..4e3c92fdfd 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -543,9 +543,6 @@ # http://crbug/v8/10905 'language/identifier-resolution/assign-to-global-undefined': [FAIL], - # http://crbug/v8/11530 - 'built-ins/Function/internals/Call/class-ctor-realm': [FAIL], - # http://crbug/v8/11531 'built-ins/RegExp/prototype/flags/get-order': [FAIL],