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

Side by Side Diff: src/builtins.cc

Issue 1500543002: [es6] Unify ArrayBuffer and SharedArrayBuffer constructors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Get the exceptions right. Other fixes. Created 4 years, 11 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/heap/heap.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 2111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 BUILTIN(ObjectProtoToString) { 2122 BUILTIN(ObjectProtoToString) {
2123 HandleScope scope(isolate); 2123 HandleScope scope(isolate);
2124 Handle<Object> object = args.at<Object>(0); 2124 Handle<Object> object = args.at<Object>(0);
2125 Handle<String> result; 2125 Handle<String> result;
2126 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2126 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2127 isolate, result, JSObject::ObjectProtoToString(isolate, object)); 2127 isolate, result, JSObject::ObjectProtoToString(isolate, object));
2128 return *result; 2128 return *result;
2129 } 2129 }
2130 2130
2131 2131
2132 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case.
2133 BUILTIN(ArrayBufferConstructor) {
2134 HandleScope scope(isolate);
2135 Handle<JSFunction> target = args.target();
2136 DCHECK(*target == target->native_context()->array_buffer_fun() ||
2137 *target == target->native_context()->shared_array_buffer_fun());
2138 THROW_NEW_ERROR_RETURN_FAILURE(
2139 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
2140 handle(target->shared()->name(), isolate)));
2141 }
2142
2143
2144 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case.
2145 BUILTIN(ArrayBufferConstructor_ConstructStub) {
2146 HandleScope scope(isolate);
2147 Handle<JSFunction> target = args.target();
2148 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
2149 Handle<Object> length = args.atOrUndefined(isolate, 1);
2150 DCHECK(*target == target->native_context()->array_buffer_fun() ||
2151 *target == target->native_context()->shared_array_buffer_fun());
2152 Handle<Object> number_length;
2153 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length,
2154 Object::ToInteger(isolate, length));
2155 if (number_length->Number() < 0.0) {
2156 THROW_NEW_ERROR_RETURN_FAILURE(
2157 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
2158 }
2159 Handle<Map> initial_map;
2160 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2161 isolate, initial_map,
2162 JSFunction::GetDerivedMap(isolate, target, new_target));
2163 size_t byte_length;
2164 if (!TryNumberToSize(isolate, *number_length, &byte_length)) {
2165 THROW_NEW_ERROR_RETURN_FAILURE(
2166 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
2167 }
2168 Handle<JSArrayBuffer> result = Handle<JSArrayBuffer>::cast(
2169 isolate->factory()->NewJSObjectFromMap(initial_map));
2170 SharedFlag shared_flag =
2171 (*target == target->native_context()->array_buffer_fun())
2172 ? SharedFlag::kNotShared
2173 : SharedFlag::kShared;
2174 if (!JSArrayBuffer::SetupAllocatingData(result, isolate, byte_length, true,
2175 shared_flag)) {
2176 THROW_NEW_ERROR_RETURN_FAILURE(
2177 isolate, NewRangeError(MessageTemplate::kArrayBufferAllocationFailed));
2178 }
2179 return *result;
2180 }
2181
2182
2183 // ES6 section 24.1.3.1 ArrayBuffer.isView ( arg )
2184 BUILTIN(ArrayBufferIsView) {
2185 SealHandleScope shs(isolate);
2186 DCHECK_EQ(2, args.length());
2187 Object* arg = args[1];
2188 return isolate->heap()->ToBoolean(arg->IsJSArrayBufferView());
2189 }
2190
2191
2132 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case. 2192 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case.
2133 BUILTIN(ProxyConstructor) { 2193 BUILTIN(ProxyConstructor) {
2134 HandleScope scope(isolate); 2194 HandleScope scope(isolate);
2135 THROW_NEW_ERROR_RETURN_FAILURE( 2195 THROW_NEW_ERROR_RETURN_FAILURE(
2136 isolate, 2196 isolate,
2137 NewTypeError(MessageTemplate::kConstructorNotFunction, 2197 NewTypeError(MessageTemplate::kConstructorNotFunction,
2138 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); 2198 isolate->factory()->NewStringFromAsciiChecked("Proxy")));
2139 } 2199 }
2140 2200
2141 2201
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 2837 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
2778 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 2838 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
2779 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 2839 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
2780 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 2840 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
2781 #undef DEFINE_BUILTIN_ACCESSOR_C 2841 #undef DEFINE_BUILTIN_ACCESSOR_C
2782 #undef DEFINE_BUILTIN_ACCESSOR_A 2842 #undef DEFINE_BUILTIN_ACCESSOR_A
2783 2843
2784 2844
2785 } // namespace internal 2845 } // namespace internal
2786 } // namespace v8 2846 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698