Commit 528bb4b9 authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Use JSObject::New in C++ builtins.

We already have a proper abstraction for dealing with subclassable
builtins, namely JSObject::New, so we should use that instead of
inlining this rather complex code sequence multiple times.

R=verwaest@chromium.org

Review URL: https://codereview.chromium.org/1709563003

Cr-Commit-Position: refs/heads/master@{#34094}
parent 28690715
...@@ -2344,13 +2344,11 @@ BUILTIN(BooleanConstructor_ConstructStub) { ...@@ -2344,13 +2344,11 @@ BUILTIN(BooleanConstructor_ConstructStub) {
Handle<JSFunction> target = args.target<JSFunction>(); Handle<JSFunction> target = args.target<JSFunction>();
Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
DCHECK(*target == target->native_context()->boolean_function()); DCHECK(*target == target->native_context()->boolean_function());
Handle<Map> initial_map; Handle<JSObject> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
isolate, initial_map, JSObject::New(target, new_target));
JSFunction::GetDerivedMap(isolate, target, new_target)); Handle<JSValue>::cast(result)->set_value(
Handle<JSValue> result = Handle<JSValue>::cast( isolate->heap()->ToBoolean(value->BooleanValue()));
isolate->factory()->NewJSObjectFromMap(initial_map));
result->set_value(isolate->heap()->ToBoolean(value->BooleanValue()));
return *result; return *result;
} }
...@@ -3730,22 +3728,20 @@ BUILTIN(ArrayBufferConstructor_ConstructStub) { ...@@ -3730,22 +3728,20 @@ BUILTIN(ArrayBufferConstructor_ConstructStub) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
} }
Handle<Map> initial_map; Handle<JSObject> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
isolate, initial_map, JSObject::New(target, new_target));
JSFunction::GetDerivedMap(isolate, target, new_target));
size_t byte_length; size_t byte_length;
if (!TryNumberToSize(isolate, *number_length, &byte_length)) { if (!TryNumberToSize(isolate, *number_length, &byte_length)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
} }
Handle<JSArrayBuffer> result = Handle<JSArrayBuffer>::cast(
isolate->factory()->NewJSObjectFromMap(initial_map));
SharedFlag shared_flag = SharedFlag shared_flag =
(*target == target->native_context()->array_buffer_fun()) (*target == target->native_context()->array_buffer_fun())
? SharedFlag::kNotShared ? SharedFlag::kNotShared
: SharedFlag::kShared; : SharedFlag::kShared;
if (!JSArrayBuffer::SetupAllocatingData(result, isolate, byte_length, true, if (!JSArrayBuffer::SetupAllocatingData(Handle<JSArrayBuffer>::cast(result),
isolate, byte_length, true,
shared_flag)) { shared_flag)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kArrayBufferAllocationFailed)); isolate, NewRangeError(MessageTemplate::kArrayBufferAllocationFailed));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment