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

Unified Diff: src/builtins.cc

Issue 2090353003: Amend DataView, ArrayBuffer, and TypedArray methods to use ToIndex. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: enable test Created 4 years, 6 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') | src/js/typedarray.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index def3620b2ed2e0cbd4debd48bf14313cd9620ceb..ed29616fa4762e0640e57c7c3222a9be6993e7e9 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -3084,37 +3084,19 @@ 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));
- }
+ Object::ToIndex(isolate, byte_offset));
- // 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));
@@ -3122,27 +3104,27 @@ BUILTIN(DataViewConstructor_ConstructStub) {
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));
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));
@@ -3150,16 +3132,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') | src/js/typedarray.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698