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

Side by Side Diff: src/builtins.cc

Issue 1712163002: [builtins] Migrate the DataView constructor to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/builtins.h ('k') | src/crankshaft/hydrogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 2370 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 THROW_NEW_ERROR_RETURN_FAILURE( 2381 THROW_NEW_ERROR_RETURN_FAILURE(
2382 isolate, NewTypeError(MessageTemplate::kNotGeneric, 2382 isolate, NewTypeError(MessageTemplate::kNotGeneric,
2383 isolate->factory()->NewStringFromAsciiChecked( 2383 isolate->factory()->NewStringFromAsciiChecked(
2384 "Boolean.prototype.valueOf"))); 2384 "Boolean.prototype.valueOf")));
2385 } 2385 }
2386 return *receiver; 2386 return *receiver;
2387 } 2387 }
2388 2388
2389 2389
2390 // ----------------------------------------------------------------------------- 2390 // -----------------------------------------------------------------------------
2391 // ES6 section 24.2 DataView Objects
2392
2393
2394 // ES6 section 24.2.2 The DataView Constructor for the [[Call]] case.
2395 BUILTIN(DataViewConstructor) {
2396 HandleScope scope(isolate);
2397 THROW_NEW_ERROR_RETURN_FAILURE(
2398 isolate,
2399 NewTypeError(MessageTemplate::kConstructorNotFunction,
2400 isolate->factory()->NewStringFromAsciiChecked("DataView")));
2401 }
2402
2403
2404 // ES6 section 24.2.2 The DataView Constructor for the [[Construct]] case.
2405 BUILTIN(DataViewConstructor_ConstructStub) {
2406 HandleScope scope(isolate);
2407 Handle<JSFunction> target = args.target<JSFunction>();
2408 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
2409 Handle<Object> buffer = args.atOrUndefined(isolate, 1);
2410 Handle<Object> byte_offset = args.atOrUndefined(isolate, 2);
2411 Handle<Object> byte_length = args.atOrUndefined(isolate, 3);
2412
2413 // 2. If Type(buffer) is not Object, throw a TypeError exception.
2414 // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a
2415 // TypeError exception.
2416 if (!buffer->IsJSArrayBuffer()) {
2417 THROW_NEW_ERROR_RETURN_FAILURE(
2418 isolate, NewTypeError(MessageTemplate::kDataViewNotArrayBuffer));
2419 }
2420 Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer>::cast(buffer);
2421
2422 // 4. Let numberOffset be ? ToNumber(byteOffset).
2423 Handle<Object> number_offset;
2424 if (byte_offset->IsUndefined()) {
2425 // We intentionally violate the specification at this point to allow
2426 // for new DataView(buffer) invocations to be equivalent to the full
2427 // new DataView(buffer, 0) invocation.
2428 number_offset = handle(Smi::FromInt(0), isolate);
2429 } else {
2430 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_offset,
2431 Object::ToNumber(byte_offset));
2432 }
2433
2434 // 5. Let offset be ToInteger(numberOffset).
2435 Handle<Object> offset;
2436 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, offset,
2437 Object::ToInteger(isolate, number_offset));
2438
2439 // 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
2440 if (number_offset->Number() != offset->Number() || offset->Number() < 0.0) {
2441 THROW_NEW_ERROR_RETURN_FAILURE(
2442 isolate, NewRangeError(MessageTemplate::kInvalidDataViewOffset));
2443 }
2444
2445 // 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
2446 // We currently violate the specification at this point.
2447
2448 // 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]]
2449 // internal slot.
2450 double const buffer_byte_length = array_buffer->byte_length()->Number();
2451
2452 // 9. If offset > bufferByteLength, throw a RangeError exception
2453 if (offset->Number() > buffer_byte_length) {
2454 THROW_NEW_ERROR_RETURN_FAILURE(
2455 isolate, NewRangeError(MessageTemplate::kInvalidDataViewOffset));
2456 }
2457
2458 Handle<Object> view_byte_length;
2459 if (byte_length->IsUndefined()) {
2460 // 10. If byteLength is undefined, then
2461 // a. Let viewByteLength be bufferByteLength - offset.
2462 view_byte_length =
2463 isolate->factory()->NewNumber(buffer_byte_length - offset->Number());
2464 } else {
2465 // 11. Else,
2466 // a. Let viewByteLength be ? ToLength(byteLength).
2467 // b. If offset+viewByteLength > bufferByteLength, throw a RangeError
2468 // exception
2469 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2470 isolate, view_byte_length, Object::ToLength(isolate, byte_length));
2471 if (offset->Number() + view_byte_length->Number() > buffer_byte_length) {
2472 THROW_NEW_ERROR_RETURN_FAILURE(
2473 isolate, NewRangeError(MessageTemplate::kInvalidDataViewLength));
2474 }
2475 }
2476
2477 // 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
2478 // "%DataViewPrototype%", «[[DataView]], [[ViewedArrayBuffer]],
2479 // [[ByteLength]], [[ByteOffset]]»).
2480 // 13. Set O's [[DataView]] internal slot to true.
2481 Handle<JSObject> result;
2482 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
2483 JSObject::New(target, new_target));
2484 for (int i = 0; i < ArrayBufferView::kInternalFieldCount; ++i) {
2485 Handle<JSDataView>::cast(result)->SetInternalField(i, Smi::FromInt(0));
2486 }
2487
2488 // 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
2489 Handle<JSDataView>::cast(result)->set_buffer(*array_buffer);
2490
2491 // 15. Set O's [[ByteLength]] internal slot to viewByteLength.
2492 Handle<JSDataView>::cast(result)->set_byte_length(*view_byte_length);
2493
2494 // 16. Set O's [[ByteOffset]] internal slot to offset.
2495 Handle<JSDataView>::cast(result)->set_byte_offset(*offset);
2496
2497 // 17. Return O.
2498 return *result;
2499 }
2500
2501
2502 // -----------------------------------------------------------------------------
2391 // ES6 section 20.3 Date Objects 2503 // ES6 section 20.3 Date Objects
2392 2504
2393 2505
2394 namespace { 2506 namespace {
2395 2507
2396 // ES6 section 20.3.1.1 Time Values and Time Range 2508 // ES6 section 20.3.1.1 Time Values and Time Range
2397 const double kMinYear = -1000000.0; 2509 const double kMinYear = -1000000.0;
2398 const double kMaxYear = -kMinYear; 2510 const double kMaxYear = -kMinYear;
2399 const double kMinMonth = -10000000.0; 2511 const double kMinMonth = -10000000.0;
2400 const double kMaxMonth = -kMinMonth; 2512 const double kMaxMonth = -kMinMonth;
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
4447 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4559 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4448 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4560 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4449 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4561 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4450 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4562 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4451 #undef DEFINE_BUILTIN_ACCESSOR_C 4563 #undef DEFINE_BUILTIN_ACCESSOR_C
4452 #undef DEFINE_BUILTIN_ACCESSOR_A 4564 #undef DEFINE_BUILTIN_ACCESSOR_A
4453 4565
4454 4566
4455 } // namespace internal 4567 } // namespace internal
4456 } // namespace v8 4568 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/crankshaft/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698