| OLD | NEW |
| 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 Loading... |
| 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->IsConstructor()); | 162 RUNTIME_ASSERT(fun->should_have_prototype()); |
| 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 Loading... |
| 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 SealHandleScope shs(isolate); | 273 HandleScope handles(isolate); |
| 274 DCHECK_EQ(1, args.length()); | 274 RUNTIME_ASSERT(args.length() == 1); |
| 275 CONVERT_ARG_CHECKED(Object, object, 0); | 275 |
| 276 return isolate->heap()->ToBoolean(object->IsConstructor()); | 276 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 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(); |
| 277 } | 297 } |
| 278 | 298 |
| 279 | 299 |
| 280 RUNTIME_FUNCTION(Runtime_SetForceInlineFlag) { | 300 RUNTIME_FUNCTION(Runtime_SetForceInlineFlag) { |
| 281 SealHandleScope shs(isolate); | 301 SealHandleScope shs(isolate); |
| 282 RUNTIME_ASSERT(args.length() == 1); | 302 RUNTIME_ASSERT(args.length() == 1); |
| 283 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 303 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 284 | 304 |
| 285 if (object->IsJSFunction()) { | 305 if (object->IsJSFunction()) { |
| 286 JSFunction* func = JSFunction::cast(*object); | 306 JSFunction* func = JSFunction::cast(*object); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 430 |
| 411 // The new function should have the same [[Prototype]] as the bindee. | 431 // The new function should have the same [[Prototype]] as the bindee. |
| 412 Handle<Map> bound_function_map( | 432 Handle<Map> bound_function_map( |
| 413 isolate->native_context()->bound_function_map()); | 433 isolate->native_context()->bound_function_map()); |
| 414 PrototypeIterator iter(isolate, bindee); | 434 PrototypeIterator iter(isolate, bindee); |
| 415 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); | 435 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); |
| 416 if (bound_function_map->prototype() != *proto) { | 436 if (bound_function_map->prototype() != *proto) { |
| 417 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto, | 437 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto, |
| 418 REGULAR_PROTOTYPE); | 438 REGULAR_PROTOTYPE); |
| 419 } | 439 } |
| 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 } | |
| 424 JSObject::MigrateToMap(bound_function, bound_function_map); | 440 JSObject::MigrateToMap(bound_function, bound_function_map); |
| 425 | 441 |
| 426 Handle<String> length_string = isolate->factory()->length_string(); | 442 Handle<String> length_string = isolate->factory()->length_string(); |
| 427 // These attributes must be kept in sync with how the bootstrapper | 443 // These attributes must be kept in sync with how the bootstrapper |
| 428 // configures the bound_function_map retrieved above. | 444 // configures the bound_function_map retrieved above. |
| 429 // We use ...IgnoreAttributes() here because of length's read-onliness. | 445 // We use ...IgnoreAttributes() here because of length's read-onliness. |
| 430 PropertyAttributes attr = | 446 PropertyAttributes attr = |
| 431 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 447 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 432 RETURN_FAILURE_ON_EXCEPTION( | 448 RETURN_FAILURE_ON_EXCEPTION( |
| 433 isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 449 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 618 |
| 603 | 619 |
| 604 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { | 620 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { |
| 605 HandleScope scope(isolate); | 621 HandleScope scope(isolate); |
| 606 DCHECK(args.length() == 0); | 622 DCHECK(args.length() == 0); |
| 607 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 623 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
| 608 NewTypeError(MessageTemplate::kStrongArity)); | 624 NewTypeError(MessageTemplate::kStrongArity)); |
| 609 } | 625 } |
| 610 } // namespace internal | 626 } // namespace internal |
| 611 } // namespace v8 | 627 } // namespace v8 |
| OLD | NEW |