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

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

Issue 1358423002: [es6] Introduce spec compliant IsConstructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix stupid fuzzer failure (constructor bit set on sloppy/strict arguments). Fix MIPS/MIPS64 typos, … Created 5 years, 2 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-classes.cc ('k') | src/runtime/runtime-object.cc » ('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/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/cpu-profiler.h" 10 #include "src/cpu-profiler.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return isolate->heap()->undefined_value(); 152 return isolate->heap()->undefined_value();
153 } 153 }
154 154
155 155
156 RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) { 156 RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) {
157 HandleScope scope(isolate); 157 HandleScope scope(isolate);
158 DCHECK(args.length() == 2); 158 DCHECK(args.length() == 2);
159 159
160 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); 160 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
161 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 161 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
162 RUNTIME_ASSERT(fun->should_have_prototype()); 162 RUNTIME_ASSERT(fun->IsConstructor());
163 RETURN_FAILURE_ON_EXCEPTION(isolate, 163 RETURN_FAILURE_ON_EXCEPTION(isolate,
164 Accessors::FunctionSetPrototype(fun, value)); 164 Accessors::FunctionSetPrototype(fun, value));
165 return args[0]; // return TOS 165 return args[0]; // return TOS
166 } 166 }
167 167
168 168
169 RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) { 169 RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
170 SealHandleScope shs(isolate); 170 SealHandleScope shs(isolate);
171 DCHECK(args.length() == 1); 171 DCHECK(args.length() == 1);
172 172
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 if (object->IsJSFunction()) { 264 if (object->IsJSFunction()) {
265 JSFunction* func = JSFunction::cast(object); 265 JSFunction* func = JSFunction::cast(object);
266 func->shared()->set_native(true); 266 func->shared()->set_native(true);
267 } 267 }
268 return isolate->heap()->undefined_value(); 268 return isolate->heap()->undefined_value();
269 } 269 }
270 270
271 271
272 RUNTIME_FUNCTION(Runtime_IsConstructor) { 272 RUNTIME_FUNCTION(Runtime_IsConstructor) {
273 HandleScope handles(isolate); 273 SealHandleScope shs(isolate);
274 RUNTIME_ASSERT(args.length() == 1); 274 DCHECK_EQ(1, args.length());
275 275 CONVERT_ARG_CHECKED(Object, object, 0);
276 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 276 return isolate->heap()->ToBoolean(object->IsConstructor());
277
278 // TODO(caitp): implement this in a better/simpler way, allow inlining via TF
279 if (object->IsJSFunction()) {
280 Handle<JSFunction> func = Handle<JSFunction>::cast(object);
281 bool should_have_prototype = func->should_have_prototype();
282 if (func->shared()->bound()) {
283 Handle<FixedArray> bound_args =
284 Handle<FixedArray>(FixedArray::cast(func->function_bindings()));
285 Handle<Object> bound_function(
286 JSReceiver::cast(bound_args->get(JSFunction::kBoundFunctionIndex)),
287 isolate);
288 if (bound_function->IsJSFunction()) {
289 Handle<JSFunction> bound = Handle<JSFunction>::cast(bound_function);
290 DCHECK(!bound->shared()->bound());
291 should_have_prototype = bound->should_have_prototype();
292 }
293 }
294 return isolate->heap()->ToBoolean(should_have_prototype);
295 }
296 return isolate->heap()->false_value();
297 } 277 }
298 278
299 279
300 RUNTIME_FUNCTION(Runtime_SetForceInlineFlag) { 280 RUNTIME_FUNCTION(Runtime_SetForceInlineFlag) {
301 SealHandleScope shs(isolate); 281 SealHandleScope shs(isolate);
302 RUNTIME_ASSERT(args.length() == 1); 282 RUNTIME_ASSERT(args.length() == 1);
303 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 283 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
304 284
305 if (object->IsJSFunction()) { 285 if (object->IsJSFunction()) {
306 JSFunction* func = JSFunction::cast(*object); 286 JSFunction* func = JSFunction::cast(*object);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 410
431 // The new function should have the same [[Prototype]] as the bindee. 411 // The new function should have the same [[Prototype]] as the bindee.
432 Handle<Map> bound_function_map( 412 Handle<Map> bound_function_map(
433 isolate->native_context()->bound_function_map()); 413 isolate->native_context()->bound_function_map());
434 PrototypeIterator iter(isolate, bindee); 414 PrototypeIterator iter(isolate, bindee);
435 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); 415 Handle<Object> proto = PrototypeIterator::GetCurrent(iter);
436 if (bound_function_map->prototype() != *proto) { 416 if (bound_function_map->prototype() != *proto) {
437 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto, 417 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto,
438 REGULAR_PROTOTYPE); 418 REGULAR_PROTOTYPE);
439 } 419 }
420 if (bound_function_map->is_constructor() != bindee->IsConstructor()) {
421 bound_function_map = Map::Copy(bound_function_map, "IsConstructor");
422 bound_function_map->set_is_constructor(bindee->IsConstructor());
423 }
440 JSObject::MigrateToMap(bound_function, bound_function_map); 424 JSObject::MigrateToMap(bound_function, bound_function_map);
441 425
442 Handle<String> length_string = isolate->factory()->length_string(); 426 Handle<String> length_string = isolate->factory()->length_string();
443 // These attributes must be kept in sync with how the bootstrapper 427 // These attributes must be kept in sync with how the bootstrapper
444 // configures the bound_function_map retrieved above. 428 // configures the bound_function_map retrieved above.
445 // We use ...IgnoreAttributes() here because of length's read-onliness. 429 // We use ...IgnoreAttributes() here because of length's read-onliness.
446 PropertyAttributes attr = 430 PropertyAttributes attr =
447 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); 431 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
448 RETURN_FAILURE_ON_EXCEPTION( 432 RETURN_FAILURE_ON_EXCEPTION(
449 isolate, JSObject::SetOwnPropertyIgnoreAttributes( 433 isolate, JSObject::SetOwnPropertyIgnoreAttributes(
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 602
619 603
620 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { 604 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) {
621 HandleScope scope(isolate); 605 HandleScope scope(isolate);
622 DCHECK(args.length() == 0); 606 DCHECK(args.length() == 0);
623 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 607 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
624 NewTypeError(MessageTemplate::kStrongArity)); 608 NewTypeError(MessageTemplate::kStrongArity));
625 } 609 }
626 } // namespace internal 610 } // namespace internal
627 } // namespace v8 611 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-classes.cc ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698