Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: src/builtins/builtins-dataview.cc

Issue 2247073004: Reland of Amend DataView, ArrayBuffer, and TypedArray methods to use ToIndex. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Correct messages Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/js/runtime.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-dataview.cc
diff --git a/src/builtins/builtins-dataview.cc b/src/builtins/builtins-dataview.cc
index 0bf2799686b3f3f67fa55b9aff898b8ab859fc4a..32c5a83d2f9cd6f0a2e939881e51fc3e871b4e47 100644
--- a/src/builtins/builtins-dataview.cc
+++ b/src/builtins/builtins-dataview.cc
@@ -38,65 +38,52 @@ BUILTIN(DataViewConstructor_ConstructStub) {
}
Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer>::cast(buffer);
- // 4. Let numberOffset be ? ToNumber(byteOffset).
- Handle<Object> number_offset;
- if (byte_offset->IsUndefined(isolate)) {
- // We intentionally violate the specification at this point to allow
- // for new DataView(buffer) invocations to be equivalent to the full
- // new DataView(buffer, 0) invocation.
- number_offset = handle(Smi::FromInt(0), isolate);
- } else {
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_offset,
- Object::ToNumber(byte_offset));
- }
-
- // 5. Let offset be ToInteger(numberOffset).
+ // 4. Let offset be ToIndex(byteOffset).
Handle<Object> offset;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, offset,
- Object::ToInteger(isolate, number_offset));
-
- // 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
- if (number_offset->Number() != offset->Number() || offset->Number() < 0.0) {
- THROW_NEW_ERROR_RETURN_FAILURE(
- isolate, NewRangeError(MessageTemplate::kInvalidDataViewOffset));
- }
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, offset,
+ Object::ToIndex(isolate, byte_offset,
+ MessageTemplate::kInvalidDataViewOffset));
- // 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
// We currently violate the specification at this point.
- // 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]]
+ // 6. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]]
// internal slot.
double const buffer_byte_length = array_buffer->byte_length()->Number();
- // 9. 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::kInvalidDataViewOffset));
+ isolate,
+ NewRangeError(MessageTemplate::kInvalidDataViewOffset, offset));
}
Handle<Object> view_byte_length;
if (byte_length->IsUndefined(isolate)) {
- // 10. If byteLength is undefined, then
+ // 8. If byteLength is undefined, then
// a. Let viewByteLength be bufferByteLength - offset.
view_byte_length =
isolate->factory()->NewNumber(buffer_byte_length - offset->Number());
} else {
- // 11. Else,
- // a. Let viewByteLength be ? ToLength(byteLength).
+ // 9. Else,
+ // a. Let viewByteLength be ? ToIndex(byteLength).
// b. If offset+viewByteLength > bufferByteLength, throw a RangeError
// exception
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, view_byte_length,
- Object::ToLength(isolate, byte_length));
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, view_byte_length,
+ Object::ToIndex(isolate, byte_length,
+ MessageTemplate::kInvalidDataViewLength));
if (offset->Number() + view_byte_length->Number() > buffer_byte_length) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidDataViewLength));
}
}
- // 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
+ // 10. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
// "%DataViewPrototype%", «[[DataView]], [[ViewedArrayBuffer]],
// [[ByteLength]], [[ByteOffset]]»).
- // 13. Set O's [[DataView]] internal slot to true.
+ // 11. Set O's [[DataView]] internal slot to true.
Handle<JSObject> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
JSObject::New(target, new_target));
@@ -104,16 +91,16 @@ BUILTIN(DataViewConstructor_ConstructStub) {
Handle<JSDataView>::cast(result)->SetInternalField(i, Smi::FromInt(0));
}
- // 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
+ // 12. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
Handle<JSDataView>::cast(result)->set_buffer(*array_buffer);
- // 15. Set O's [[ByteLength]] internal slot to viewByteLength.
+ // 13. Set O's [[ByteLength]] internal slot to viewByteLength.
Handle<JSDataView>::cast(result)->set_byte_length(*view_byte_length);
- // 16. Set O's [[ByteOffset]] internal slot to offset.
+ // 14. Set O's [[ByteOffset]] internal slot to offset.
Handle<JSDataView>::cast(result)->set_byte_offset(*offset);
- // 17. Return O.
+ // 15. Return O.
return *result;
}
« no previous file with comments | « no previous file | src/js/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698