| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // BUILTIN(name) { | 120 // BUILTIN(name) { |
| 121 // ... | 121 // ... |
| 122 // } | 122 // } |
| 123 // | 123 // |
| 124 // In the body of the builtin function the arguments can be accessed | 124 // In the body of the builtin function the arguments can be accessed |
| 125 // through the BuiltinArguments object args. | 125 // through the BuiltinArguments object args. |
| 126 | 126 |
| 127 #ifdef DEBUG | 127 #ifdef DEBUG |
| 128 | 128 |
| 129 #define BUILTIN(name) \ | 129 #define BUILTIN(name) \ |
| 130 MUST_USE_RESULT static MaybeObject* Builtin_Impl_##name( \ | 130 MUST_USE_RESULT static Object* Builtin_Impl_##name( \ |
| 131 name##ArgumentsType args, Isolate* isolate); \ | 131 name##ArgumentsType args, Isolate* isolate); \ |
| 132 MUST_USE_RESULT static MaybeObject* Builtin_##name( \ | 132 MUST_USE_RESULT static Object* Builtin_##name( \ |
| 133 int args_length, Object** args_object, Isolate* isolate) { \ | 133 int args_length, Object** args_object, Isolate* isolate) { \ |
| 134 name##ArgumentsType args(args_length, args_object); \ | 134 name##ArgumentsType args(args_length, args_object); \ |
| 135 args.Verify(); \ | 135 args.Verify(); \ |
| 136 return Builtin_Impl_##name(args, isolate); \ | 136 return Builtin_Impl_##name(args, isolate); \ |
| 137 } \ | 137 } \ |
| 138 MUST_USE_RESULT static MaybeObject* Builtin_Impl_##name( \ | 138 MUST_USE_RESULT static Object* Builtin_Impl_##name( \ |
| 139 name##ArgumentsType args, Isolate* isolate) | 139 name##ArgumentsType args, Isolate* isolate) |
| 140 | 140 |
| 141 #else // For release mode. | 141 #else // For release mode. |
| 142 | 142 |
| 143 #define BUILTIN(name) \ | 143 #define BUILTIN(name) \ |
| 144 static MaybeObject* Builtin_impl##name( \ | 144 static Object* Builtin_impl##name( \ |
| 145 name##ArgumentsType args, Isolate* isolate); \ | 145 name##ArgumentsType args, Isolate* isolate); \ |
| 146 static MaybeObject* Builtin_##name( \ | 146 static Object* Builtin_##name( \ |
| 147 int args_length, Object** args_object, Isolate* isolate) { \ | 147 int args_length, Object** args_object, Isolate* isolate) { \ |
| 148 name##ArgumentsType args(args_length, args_object); \ | 148 name##ArgumentsType args(args_length, args_object); \ |
| 149 return Builtin_impl##name(args, isolate); \ | 149 return Builtin_impl##name(args, isolate); \ |
| 150 } \ | 150 } \ |
| 151 static MaybeObject* Builtin_impl##name( \ | 151 static Object* Builtin_impl##name( \ |
| 152 name##ArgumentsType args, Isolate* isolate) | 152 name##ArgumentsType args, Isolate* isolate) |
| 153 #endif | 153 #endif |
| 154 | 154 |
| 155 | 155 |
| 156 #ifdef DEBUG | 156 #ifdef DEBUG |
| 157 static inline bool CalledAsConstructor(Isolate* isolate) { | 157 static inline bool CalledAsConstructor(Isolate* isolate) { |
| 158 // Calculate the result using a full stack frame iterator and check | 158 // Calculate the result using a full stack frame iterator and check |
| 159 // that the state of the stack is as we assume it to be in the | 159 // that the state of the stack is as we assume it to be in the |
| 160 // code below. | 160 // code below. |
| 161 StackFrameIterator it(isolate); | 161 StackFrameIterator it(isolate); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 if (!FLAG_clever_optimizations) return false; | 359 if (!FLAG_clever_optimizations) return false; |
| 360 DisallowHeapAllocation no_gc; | 360 DisallowHeapAllocation no_gc; |
| 361 Context* native_context = heap->isolate()->context()->native_context(); | 361 Context* native_context = heap->isolate()->context()->native_context(); |
| 362 JSObject* array_proto = | 362 JSObject* array_proto = |
| 363 JSObject::cast(native_context->array_function()->prototype()); | 363 JSObject::cast(native_context->array_function()->prototype()); |
| 364 return receiver->GetPrototype() == array_proto && | 364 return receiver->GetPrototype() == array_proto && |
| 365 ArrayPrototypeHasNoElements(heap, native_context, array_proto); | 365 ArrayPrototypeHasNoElements(heap, native_context, array_proto); |
| 366 } | 366 } |
| 367 | 367 |
| 368 | 368 |
| 369 MUST_USE_RESULT static MaybeObject* CallJsBuiltin( | 369 MUST_USE_RESULT static Object* CallJsBuiltin( |
| 370 Isolate* isolate, | 370 Isolate* isolate, |
| 371 const char* name, | 371 const char* name, |
| 372 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { | 372 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
| 373 HandleScope handleScope(isolate); | 373 HandleScope handleScope(isolate); |
| 374 | 374 |
| 375 Handle<Object> js_builtin = Object::GetProperty( | 375 Handle<Object> js_builtin = Object::GetProperty( |
| 376 isolate, | 376 isolate, |
| 377 handle(isolate->native_context()->builtins(), isolate), | 377 handle(isolate->native_context()->builtins(), isolate), |
| 378 name).ToHandleChecked(); | 378 name).ToHandleChecked(); |
| 379 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); | 379 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 int new_length = len - 1; | 522 int new_length = len - 1; |
| 523 MaybeHandle<Object> maybe_element; | 523 MaybeHandle<Object> maybe_element; |
| 524 if (accessor->HasElement(array, array, new_length, elms_obj)) { | 524 if (accessor->HasElement(array, array, new_length, elms_obj)) { |
| 525 maybe_element = accessor->Get(array, array, new_length, elms_obj); | 525 maybe_element = accessor->Get(array, array, new_length, elms_obj); |
| 526 } else { | 526 } else { |
| 527 Handle<Object> proto(array->GetPrototype(), isolate); | 527 Handle<Object> proto(array->GetPrototype(), isolate); |
| 528 maybe_element = Object::GetElement(isolate, proto, len - 1); | 528 maybe_element = Object::GetElement(isolate, proto, len - 1); |
| 529 } | 529 } |
| 530 Handle<Object> element; | 530 Handle<Object> element; |
| 531 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element); | 531 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element); |
| 532 RETURN_FAILURE_ON_EXCEPTION( | 532 RETURN_IF_EMPTY_HANDLE( |
| 533 isolate, | 533 isolate, |
| 534 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); | 534 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); |
| 535 return *element; | 535 return *element; |
| 536 } | 536 } |
| 537 | 537 |
| 538 | 538 |
| 539 BUILTIN(ArrayShift) { | 539 BUILTIN(ArrayShift) { |
| 540 HandleScope scope(isolate); | 540 HandleScope scope(isolate); |
| 541 Heap* heap = isolate->heap(); | 541 Heap* heap = isolate->heap(); |
| 542 Handle<Object> receiver = args.receiver(); | 542 Handle<Object> receiver = args.receiver(); |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 Object* current = *arg; | 1159 Object* current = *arg; |
| 1160 current = FindHidden(heap, current, FunctionTemplateInfo::cast(argtype)); | 1160 current = FindHidden(heap, current, FunctionTemplateInfo::cast(argtype)); |
| 1161 if (current == heap->null_value()) current = heap->undefined_value(); | 1161 if (current == heap->null_value()) current = heap->undefined_value(); |
| 1162 *arg = current; | 1162 *arg = current; |
| 1163 } | 1163 } |
| 1164 return holder; | 1164 return holder; |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 | 1167 |
| 1168 template <bool is_construct> | 1168 template <bool is_construct> |
| 1169 MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( | 1169 MUST_USE_RESULT static Object* HandleApiCallHelper( |
| 1170 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { | 1170 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { |
| 1171 ASSERT(is_construct == CalledAsConstructor(isolate)); | 1171 ASSERT(is_construct == CalledAsConstructor(isolate)); |
| 1172 Heap* heap = isolate->heap(); | 1172 Heap* heap = isolate->heap(); |
| 1173 | 1173 |
| 1174 HandleScope scope(isolate); | 1174 HandleScope scope(isolate); |
| 1175 Handle<JSFunction> function = args.called_function(); | 1175 Handle<JSFunction> function = args.called_function(); |
| 1176 ASSERT(function->shared()->IsApiFunction()); | 1176 ASSERT(function->shared()->IsApiFunction()); |
| 1177 | 1177 |
| 1178 Handle<FunctionTemplateInfo> fun_data( | 1178 Handle<FunctionTemplateInfo> fun_data( |
| 1179 function->shared()->get_api_func_data(), isolate); | 1179 function->shared()->get_api_func_data(), isolate); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1245 |
| 1246 | 1246 |
| 1247 BUILTIN(HandleApiCallConstruct) { | 1247 BUILTIN(HandleApiCallConstruct) { |
| 1248 return HandleApiCallHelper<true>(args, isolate); | 1248 return HandleApiCallHelper<true>(args, isolate); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 | 1251 |
| 1252 // Helper function to handle calls to non-function objects created through the | 1252 // Helper function to handle calls to non-function objects created through the |
| 1253 // API. The object can be called as either a constructor (using new) or just as | 1253 // API. The object can be called as either a constructor (using new) or just as |
| 1254 // a function (without new). | 1254 // a function (without new). |
| 1255 MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( | 1255 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( |
| 1256 Isolate* isolate, | 1256 Isolate* isolate, |
| 1257 bool is_construct_call, | 1257 bool is_construct_call, |
| 1258 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { | 1258 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
| 1259 // Non-functions are never called as constructors. Even if this is an object | 1259 // Non-functions are never called as constructors. Even if this is an object |
| 1260 // called as a constructor the delegate call is not a construct call. | 1260 // called as a constructor the delegate call is not a construct call. |
| 1261 ASSERT(!CalledAsConstructor(isolate)); | 1261 ASSERT(!CalledAsConstructor(isolate)); |
| 1262 Heap* heap = isolate->heap(); | 1262 Heap* heap = isolate->heap(); |
| 1263 | 1263 |
| 1264 Handle<Object> receiver = args.receiver(); | 1264 Handle<Object> receiver = args.receiver(); |
| 1265 | 1265 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 } | 1734 } |
| 1735 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1735 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1736 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1736 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1737 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1737 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 1738 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1738 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1739 #undef DEFINE_BUILTIN_ACCESSOR_C | 1739 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1740 #undef DEFINE_BUILTIN_ACCESSOR_A | 1740 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1741 | 1741 |
| 1742 | 1742 |
| 1743 } } // namespace v8::internal | 1743 } } // namespace v8::internal |
| OLD | NEW |