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

Side by Side Diff: src/runtime/runtime-typedarray.cc

Issue 2697013009: Move ArrayBuffer.prototype.slice implementation to C++ (Closed)
Patch Set: merge master Created 3 years, 9 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/runtime/runtime-regexp.cc ('k') | src/v8.gyp » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
11 #include "src/runtime/runtime.h" 11 #include "src/runtime/runtime.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { 16 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) {
17 SealHandleScope shs(isolate); 17 SealHandleScope shs(isolate);
18 DCHECK_EQ(1, args.length()); 18 DCHECK_EQ(1, args.length());
19 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); 19 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0);
20 return holder->byte_length(); 20 return holder->byte_length();
21 } 21 }
22 22
23 23
24 RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) {
25 HandleScope scope(isolate);
26 DCHECK_EQ(4, args.length());
27 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0);
28 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1);
29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(first, 2);
30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3);
31
32 if (source->was_neutered() || target->was_neutered()) {
33 THROW_NEW_ERROR_RETURN_FAILURE(
34 isolate, NewTypeError(MessageTemplate::kDetachedOperation,
35 isolate->factory()->NewStringFromAsciiChecked(
36 "ArrayBuffer.prototype.slice")));
37 }
38
39 CHECK(!source.is_identical_to(target));
40 size_t start = 0, target_length = 0;
41 CHECK(TryNumberToSize(*first, &start));
42 CHECK(TryNumberToSize(*new_length, &target_length));
43 CHECK(NumberToSize(target->byte_length()) >= target_length);
44
45 if (target_length == 0) return isolate->heap()->undefined_value();
46
47 size_t source_byte_length = NumberToSize(source->byte_length());
48 CHECK(start <= source_byte_length);
49 CHECK(source_byte_length - start >= target_length);
50 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store());
51 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store());
52 CopyBytes(target_data, source_data + start, target_length);
53 return isolate->heap()->undefined_value();
54 }
55
56
57 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { 24 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) {
58 HandleScope scope(isolate); 25 HandleScope scope(isolate);
59 DCHECK_EQ(1, args.length()); 26 DCHECK_EQ(1, args.length());
60 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); 27 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0);
61 if (array_buffer->backing_store() == NULL) { 28 if (array_buffer->backing_store() == NULL) {
62 CHECK(Smi::kZero == array_buffer->byte_length()); 29 CHECK(Smi::kZero == array_buffer->byte_length());
63 return isolate->heap()->undefined_value(); 30 return isolate->heap()->undefined_value();
64 } 31 }
65 // Shared array buffers should never be neutered. 32 // Shared array buffers should never be neutered.
66 CHECK(!array_buffer->is_shared()); 33 CHECK(!array_buffer->is_shared());
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return isolate->heap()->false_value(); 440 return isolate->heap()->false_value();
474 } 441 }
475 442
476 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); 443 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0]));
477 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && 444 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() &&
478 obj->type() == kExternalInt32Array); 445 obj->type() == kExternalInt32Array);
479 } 446 }
480 447
481 } // namespace internal 448 } // namespace internal
482 } // namespace v8 449 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-regexp.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698