| 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 25 matching lines...) Expand all Loading... |
| 36 #include "frames-inl.h" | 36 #include "frames-inl.h" |
| 37 #include "isolate.h" | 37 #include "isolate.h" |
| 38 #include "list-inl.h" | 38 #include "list-inl.h" |
| 39 #include "property-details.h" | 39 #include "property-details.h" |
| 40 | 40 |
| 41 namespace v8 { | 41 namespace v8 { |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 | 44 |
| 45 template <class C> | 45 template <class C> |
| 46 static C* FindInstanceOf(Isolate* isolate, Object* obj) { | 46 static Handle<C> FindInstanceOf(Isolate* isolate, Handle<Object> obj) { |
| 47 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { | 47 for (Handle<Object> cur = obj; |
| 48 if (Is<C>(cur)) return C::cast(cur); | 48 !cur->IsNull(); |
| 49 cur = Object::GetPrototype(isolate, cur)) { |
| 50 if (Is<C>(*cur)) return Handle<C>::cast(cur); |
| 49 } | 51 } |
| 50 return NULL; | 52 return Handle<C>::null(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 | 55 |
| 54 // Entry point that never should be called. | 56 // Entry point that never should be called. |
| 55 MaybeObject* Accessors::IllegalSetter(Isolate* isolate, | 57 MaybeObject* Accessors::IllegalSetter(Isolate* isolate, |
| 56 JSObject*, | 58 JSObject*, |
| 57 Object*, | 59 Object*, |
| 58 void*) { | 60 void*) { |
| 59 UNREACHABLE(); | 61 UNREACHABLE(); |
| 60 return NULL; | 62 return NULL; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 152 |
| 151 // | 153 // |
| 152 // Accessors::ArrayLength | 154 // Accessors::ArrayLength |
| 153 // | 155 // |
| 154 | 156 |
| 155 | 157 |
| 156 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, | 158 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, |
| 157 Object* object, | 159 Object* object, |
| 158 void*) { | 160 void*) { |
| 159 // Traverse the prototype chain until we reach an array. | 161 // Traverse the prototype chain until we reach an array. |
| 160 JSArray* holder = FindInstanceOf<JSArray>(isolate, object); | 162 Handle<JSArray> holder = |
| 161 return holder == NULL ? Smi::FromInt(0) : holder->length(); | 163 FindInstanceOf<JSArray>(isolate, handle(object, isolate)); |
| 164 return holder.is_null() ? Smi::FromInt(0) : holder->length(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 | 167 |
| 165 // The helper function will 'flatten' Number objects. | 168 // The helper function will 'flatten' Number objects. |
| 166 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, | 169 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, |
| 167 Handle<Object> value) { | 170 Handle<Object> value) { |
| 168 if (value->IsNumber() || !value->IsJSValue()) return value; | 171 if (value->IsNumber() || !value->IsJSValue()) return value; |
| 169 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); | 172 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); |
| 170 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> | 173 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> |
| 171 has_initial_map()); | 174 has_initial_map()); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 *function, | 557 *function, |
| 555 *prototype, | 558 *prototype, |
| 556 NULL), | 559 NULL), |
| 557 Object); | 560 Object); |
| 558 } | 561 } |
| 559 | 562 |
| 560 | 563 |
| 561 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, | 564 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, |
| 562 Object* object, | 565 Object* object, |
| 563 void*) { | 566 void*) { |
| 564 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); | 567 HandleScope scope(isolate); |
| 565 if (function_raw == NULL) return isolate->heap()->undefined_value(); | 568 Handle<JSFunction> function = |
| 566 while (!function_raw->should_have_prototype()) { | 569 FindInstanceOf<JSFunction>(isolate, handle(object, isolate)); |
| 567 function_raw = FindInstanceOf<JSFunction>(isolate, | 570 if (function.is_null()) return isolate->heap()->undefined_value(); |
| 568 function_raw->GetPrototype()); | 571 while (!function->should_have_prototype()) { |
| 572 function = FindInstanceOf<JSFunction>( |
| 573 isolate, |
| 574 Object::GetPrototype(isolate, function)); |
| 569 // There has to be one because we hit the getter. | 575 // There has to be one because we hit the getter. |
| 570 ASSERT(function_raw != NULL); | 576 ASSERT(!function.is_null()); |
| 571 } | 577 } |
| 572 | 578 |
| 573 if (!function_raw->has_prototype()) { | 579 if (!function->has_prototype()) { |
| 574 HandleScope scope(isolate); | |
| 575 Handle<JSFunction> function(function_raw); | |
| 576 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); | 580 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); |
| 577 JSFunction::SetPrototype(function, proto); | 581 JSFunction::SetPrototype(function, proto); |
| 578 function_raw = *function; | |
| 579 } | 582 } |
| 580 return function_raw->prototype(); | 583 return function->prototype(); |
| 581 } | 584 } |
| 582 | 585 |
| 583 | 586 |
| 584 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, | 587 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, |
| 585 JSObject* object_raw, | 588 JSObject* object_raw, |
| 586 Object* value_raw, | 589 Object* value_raw, |
| 587 void*) { | 590 void*) { |
| 588 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw); | |
| 589 if (function_raw == NULL) return isolate->heap()->undefined_value(); | |
| 590 | |
| 591 HandleScope scope(isolate); | 591 HandleScope scope(isolate); |
| 592 Handle<JSFunction> function(function_raw, isolate); | |
| 593 Handle<JSObject> object(object_raw, isolate); | 592 Handle<JSObject> object(object_raw, isolate); |
| 594 Handle<Object> value(value_raw, isolate); | 593 Handle<Object> value(value_raw, isolate); |
| 594 Handle<JSFunction> function = FindInstanceOf<JSFunction>(isolate, object); |
| 595 if (function.is_null()) return isolate->heap()->undefined_value(); |
| 596 |
| 595 if (!function->should_have_prototype()) { | 597 if (!function->should_have_prototype()) { |
| 596 // Since we hit this accessor, object will have no prototype property. | 598 // Since we hit this accessor, object will have no prototype property. |
| 597 Handle<Object> result; | 599 Handle<Object> result; |
| 598 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 600 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 599 isolate, result, | 601 isolate, result, |
| 600 JSObject::SetLocalPropertyIgnoreAttributes( | 602 JSObject::SetLocalPropertyIgnoreAttributes( |
| 601 object, isolate->factory()->prototype_string(), value, NONE)); | 603 object, isolate->factory()->prototype_string(), value, NONE)); |
| 602 return *result; | 604 return *result; |
| 603 } | 605 } |
| 604 | 606 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 631 | 633 |
| 632 | 634 |
| 633 // | 635 // |
| 634 // Accessors::FunctionLength | 636 // Accessors::FunctionLength |
| 635 // | 637 // |
| 636 | 638 |
| 637 | 639 |
| 638 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, | 640 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, |
| 639 Object* object, | 641 Object* object, |
| 640 void*) { | 642 void*) { |
| 641 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); | 643 HandleScope scope(isolate); |
| 642 if (function == NULL) return Smi::FromInt(0); | 644 Handle<JSFunction> function = |
| 645 FindInstanceOf<JSFunction>(isolate, handle(object, isolate)); |
| 646 if (function.is_null()) return Smi::FromInt(0); |
| 643 // Check if already compiled. | 647 // Check if already compiled. |
| 644 if (function->shared()->is_compiled()) { | 648 if (function->shared()->is_compiled()) { |
| 645 return Smi::FromInt(function->shared()->length()); | 649 return Smi::FromInt(function->shared()->length()); |
| 646 } | 650 } |
| 647 // If the function isn't compiled yet, the length is not computed correctly | 651 // If the function isn't compiled yet, the length is not computed correctly |
| 648 // yet. Compile it now and return the right length. | 652 // yet. Compile it now and return the right length. |
| 649 HandleScope scope(isolate); | 653 if (Compiler::EnsureCompiled(function, KEEP_EXCEPTION)) { |
| 650 Handle<JSFunction> function_handle(function); | 654 return Smi::FromInt(function->shared()->length()); |
| 651 if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) { | |
| 652 return Smi::FromInt(function_handle->shared()->length()); | |
| 653 } | 655 } |
| 654 return Failure::Exception(); | 656 return Failure::Exception(); |
| 655 } | 657 } |
| 656 | 658 |
| 657 | 659 |
| 658 const AccessorDescriptor Accessors::FunctionLength = { | 660 const AccessorDescriptor Accessors::FunctionLength = { |
| 659 FunctionGetLength, | 661 FunctionGetLength, |
| 660 ReadOnlySetAccessor, | 662 ReadOnlySetAccessor, |
| 661 0 | 663 0 |
| 662 }; | 664 }; |
| 663 | 665 |
| 664 | 666 |
| 665 // | 667 // |
| 666 // Accessors::FunctionName | 668 // Accessors::FunctionName |
| 667 // | 669 // |
| 668 | 670 |
| 669 | 671 |
| 670 MaybeObject* Accessors::FunctionGetName(Isolate* isolate, | 672 MaybeObject* Accessors::FunctionGetName(Isolate* isolate, |
| 671 Object* object, | 673 Object* object, |
| 672 void*) { | 674 void*) { |
| 673 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 675 HandleScope scope(isolate); |
| 674 return holder == NULL | 676 Handle<JSFunction> holder = |
| 677 FindInstanceOf<JSFunction>(isolate, handle(object, isolate)); |
| 678 return holder.is_null() |
| 675 ? isolate->heap()->undefined_value() | 679 ? isolate->heap()->undefined_value() |
| 676 : holder->shared()->name(); | 680 : holder->shared()->name(); |
| 677 } | 681 } |
| 678 | 682 |
| 679 | 683 |
| 680 const AccessorDescriptor Accessors::FunctionName = { | 684 const AccessorDescriptor Accessors::FunctionName = { |
| 681 FunctionGetName, | 685 FunctionGetName, |
| 682 ReadOnlySetAccessor, | 686 ReadOnlySetAccessor, |
| 683 0 | 687 0 |
| 684 }; | 688 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 727 |
| 724 // Return the freshly allocated arguments object. | 728 // Return the freshly allocated arguments object. |
| 725 return *arguments; | 729 return *arguments; |
| 726 } | 730 } |
| 727 | 731 |
| 728 | 732 |
| 729 MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate, | 733 MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate, |
| 730 Object* object, | 734 Object* object, |
| 731 void*) { | 735 void*) { |
| 732 HandleScope scope(isolate); | 736 HandleScope scope(isolate); |
| 733 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 737 Handle<JSFunction> function = |
| 734 if (holder == NULL) return isolate->heap()->undefined_value(); | 738 FindInstanceOf<JSFunction>(isolate, handle(object, isolate)); |
| 735 Handle<JSFunction> function(holder, isolate); | 739 if (function.is_null()) return isolate->heap()->undefined_value(); |
| 736 | 740 |
| 737 if (function->shared()->native()) return isolate->heap()->null_value(); | 741 if (function->shared()->native()) return isolate->heap()->null_value(); |
| 738 // Find the top invocation of the function by traversing frames. | 742 // Find the top invocation of the function by traversing frames. |
| 739 List<JSFunction*> functions(2); | 743 List<JSFunction*> functions(2); |
| 740 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { | 744 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { |
| 741 JavaScriptFrame* frame = it.frame(); | 745 JavaScriptFrame* frame = it.frame(); |
| 742 frame->GetFunctions(&functions); | 746 frame->GetFunctions(&functions); |
| 743 for (int i = functions.length() - 1; i >= 0; i--) { | 747 for (int i = functions.length() - 1; i >= 0; i--) { |
| 744 // Skip all frames that aren't invocations of the given function. | 748 // Skip all frames that aren't invocations of the given function. |
| 745 if (functions[i] != *function) continue; | 749 if (functions[i] != *function) continue; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 List<JSFunction*> functions_; | 852 List<JSFunction*> functions_; |
| 849 int index_; | 853 int index_; |
| 850 }; | 854 }; |
| 851 | 855 |
| 852 | 856 |
| 853 MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate, | 857 MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate, |
| 854 Object* object, | 858 Object* object, |
| 855 void*) { | 859 void*) { |
| 856 HandleScope scope(isolate); | 860 HandleScope scope(isolate); |
| 857 DisallowHeapAllocation no_allocation; | 861 DisallowHeapAllocation no_allocation; |
| 858 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); | 862 Handle<JSFunction> function = |
| 859 if (holder == NULL) return isolate->heap()->undefined_value(); | 863 FindInstanceOf<JSFunction>(isolate, handle(object, isolate)); |
| 860 if (holder->shared()->native()) return isolate->heap()->null_value(); | 864 if (function.is_null()) return isolate->heap()->undefined_value(); |
| 861 Handle<JSFunction> function(holder, isolate); | 865 if (function->shared()->native()) return isolate->heap()->null_value(); |
| 862 | 866 |
| 863 FrameFunctionIterator it(isolate, no_allocation); | 867 FrameFunctionIterator it(isolate, no_allocation); |
| 864 | 868 |
| 865 // Find the function from the frames. | 869 // Find the function from the frames. |
| 866 if (!it.Find(*function)) { | 870 if (!it.Find(*function)) { |
| 867 // No frame corresponding to the given function found. Return null. | 871 // No frame corresponding to the given function found. Return null. |
| 868 return isolate->heap()->null_value(); | 872 return isolate->heap()->null_value(); |
| 869 } | 873 } |
| 870 | 874 |
| 871 // Find previously called non-toplevel function. | 875 // Find previously called non-toplevel function. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 info->set_data(Smi::FromInt(index)); | 972 info->set_data(Smi::FromInt(index)); |
| 969 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 973 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
| 970 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 974 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
| 971 info->set_getter(*getter); | 975 info->set_getter(*getter); |
| 972 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 976 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 973 return info; | 977 return info; |
| 974 } | 978 } |
| 975 | 979 |
| 976 | 980 |
| 977 } } // namespace v8::internal | 981 } } // namespace v8::internal |
| OLD | NEW |