Commit fa82d01e authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[builtins] Remove DataViewConstructor_ConstructStub builtin

This brings us closer to our goal of deprecating the `construct_stub`
field in `SharedFunctionInfo`.

Bug: v8:7503
Change-Id: I9502246f5e463e487a989ab7f8c96c008f0fa9d9
Reviewed-on: https://chromium-review.googlesource.com/941143
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51634}
parent 0ffaedf8
......@@ -3035,7 +3035,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallWithIntrinsicDefaultProto(isolate, data_view_fun,
Context::DATA_VIEW_FUN_INDEX);
data_view_fun->shared()->SetConstructStub(
*BUILTIN_CODE(isolate, DataViewConstructor_ConstructStub));
*BUILTIN_CODE(isolate, JSBuiltinsConstructStub));
data_view_fun->shared()->set_length(3);
data_view_fun->shared()->DontAdaptArguments();
......
......@@ -14,20 +14,17 @@ namespace v8 {
namespace internal {
// -----------------------------------------------------------------------------
// ES6 section 24.2 DataView Objects
// ES #sec-dataview-objects
// ES6 section 24.2.2 The DataView Constructor for the [[Call]] case.
// ES #sec-dataview-constructor
BUILTIN(DataViewConstructor) {
HandleScope scope(isolate);
if (args.new_target()->IsUndefined(isolate)) { // [[Call]]
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewTypeError(MessageTemplate::kConstructorNotFunction,
isolate->factory()->NewStringFromAsciiChecked("DataView")));
}
// ES6 section 24.2.2 The DataView Constructor for the [[Construct]] case.
BUILTIN(DataViewConstructor_ConstructStub) {
HandleScope scope(isolate);
isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
isolate->factory()->NewStringFromAsciiChecked(
"DataView")));
} else { // [[Construct]]
Handle<JSFunction> target = args.target();
Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
Handle<Object> buffer = args.atOrUndefined(isolate, 1);
......@@ -43,20 +40,20 @@ BUILTIN(DataViewConstructor_ConstructStub) {
}
Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer>::cast(buffer);
// 4. Let offset be ToIndex(byteOffset).
// 4. Let offset be ? ToIndex(byteOffset).
Handle<Object> offset;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, offset,
Object::ToIndex(isolate, byte_offset, MessageTemplate::kInvalidOffset));
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
// We currently violate the specification at this point.
// We currently violate the specification at this point. TODO: Fix that.
// 6. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]]
// internal slot.
// 6. Let bufferByteLength be the value of buffer's
// [[ArrayBufferByteLength]] internal slot.
double const buffer_byte_length = array_buffer->byte_length()->Number();
// 7. If offset > bufferByteLength, throw a RangeError exception
// 7. If offset > bufferByteLength, throw a RangeError exception.
if (offset->Number() > buffer_byte_length) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidOffset, offset));
......@@ -64,15 +61,15 @@ BUILTIN(DataViewConstructor_ConstructStub) {
Handle<Object> view_byte_length;
if (byte_length->IsUndefined(isolate)) {
// 8. If byteLength is undefined, then
// 8. If byteLength is either not present or undefined, then
// a. Let viewByteLength be bufferByteLength - offset.
view_byte_length =
isolate->factory()->NewNumber(buffer_byte_length - offset->Number());
} else {
// 9. Else,
// a. Let viewByteLength be ? ToIndex(byteLength).
// b. If offset+viewByteLength > bufferByteLength, throw a RangeError
// exception
// b. If offset+viewByteLength > bufferByteLength, throw a
// RangeError exception.
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, view_byte_length,
Object::ToIndex(isolate, byte_length,
......@@ -86,7 +83,6 @@ BUILTIN(DataViewConstructor_ConstructStub) {
// 10. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
// "%DataViewPrototype%", «[[DataView]], [[ViewedArrayBuffer]],
// [[ByteLength]], [[ByteOffset]]»).
// 11. Set O's [[DataView]] internal slot to true.
Handle<JSObject> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
JSObject::New(target, new_target));
......@@ -94,17 +90,18 @@ BUILTIN(DataViewConstructor_ConstructStub) {
Handle<JSDataView>::cast(result)->SetEmbedderField(i, Smi::kZero);
}
// 12. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
// 11. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
Handle<JSDataView>::cast(result)->set_buffer(*array_buffer);
// 13. Set O's [[ByteLength]] internal slot to viewByteLength.
// 12. Set O's [[ByteLength]] internal slot to viewByteLength.
Handle<JSDataView>::cast(result)->set_byte_length(*view_byte_length);
// 14. Set O's [[ByteOffset]] internal slot to offset.
// 13. Set O's [[ByteOffset]] internal slot to offset.
Handle<JSDataView>::cast(result)->set_byte_offset(*offset);
// 15. Return O.
// 14. Return O.
return *result;
}
}
// ES6 section 24.2.4.1 get DataView.prototype.buffer
......
......@@ -434,8 +434,8 @@ namespace internal {
CPP(ConsoleContext) \
\
/* DataView */ \
/* ES #sec-dataview-constructor */ \
CPP(DataViewConstructor) \
CPP(DataViewConstructor_ConstructStub) \
CPP(DataViewPrototypeGetBuffer) \
CPP(DataViewPrototypeGetByteLength) \
CPP(DataViewPrototypeGetByteOffset) \
......
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