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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 Object* result; | 62 Object* result; |
63 { MaybeObject* maybe_result = | 63 { MaybeObject* maybe_result = |
64 constructor->GetHeap()->AllocateJSObject(constructor); | 64 constructor->GetHeap()->AllocateJSObject(constructor); |
65 if (!maybe_result->ToObject(&result)) return maybe_result; | 65 if (!maybe_result->ToObject(&result)) return maybe_result; |
66 } | 66 } |
67 JSValue::cast(result)->set_value(value); | 67 JSValue::cast(result)->set_value(value); |
68 return result; | 68 return result; |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 MaybeObject* Object::ToObject(Context* native_context) { | 72 MaybeObject* Object::ToObject(Context* global_context) { |
73 if (IsNumber()) { | 73 if (IsNumber()) { |
74 return CreateJSValue(native_context->number_function(), this); | 74 return CreateJSValue(global_context->number_function(), this); |
75 } else if (IsBoolean()) { | 75 } else if (IsBoolean()) { |
76 return CreateJSValue(native_context->boolean_function(), this); | 76 return CreateJSValue(global_context->boolean_function(), this); |
77 } else if (IsString()) { | 77 } else if (IsString()) { |
78 return CreateJSValue(native_context->string_function(), this); | 78 return CreateJSValue(global_context->string_function(), this); |
79 } | 79 } |
80 ASSERT(IsJSObject()); | 80 ASSERT(IsJSObject()); |
81 return this; | 81 return this; |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 MaybeObject* Object::ToObject() { | 85 MaybeObject* Object::ToObject() { |
86 if (IsJSReceiver()) { | 86 if (IsJSReceiver()) { |
87 return this; | 87 return this; |
88 } else if (IsNumber()) { | 88 } else if (IsNumber()) { |
89 Isolate* isolate = Isolate::Current(); | 89 Isolate* isolate = Isolate::Current(); |
90 Context* native_context = isolate->context()->native_context(); | 90 Context* global_context = isolate->context()->global_context(); |
91 return CreateJSValue(native_context->number_function(), this); | 91 return CreateJSValue(global_context->number_function(), this); |
92 } else if (IsBoolean()) { | 92 } else if (IsBoolean()) { |
93 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 93 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
94 Context* native_context = isolate->context()->native_context(); | 94 Context* global_context = isolate->context()->global_context(); |
95 return CreateJSValue(native_context->boolean_function(), this); | 95 return CreateJSValue(global_context->boolean_function(), this); |
96 } else if (IsString()) { | 96 } else if (IsString()) { |
97 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 97 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
98 Context* native_context = isolate->context()->native_context(); | 98 Context* global_context = isolate->context()->global_context(); |
99 return CreateJSValue(native_context->string_function(), this); | 99 return CreateJSValue(global_context->string_function(), this); |
100 } | 100 } |
101 | 101 |
102 // Throw a type error. | 102 // Throw a type error. |
103 return Failure::InternalError(); | 103 return Failure::InternalError(); |
104 } | 104 } |
105 | 105 |
106 | 106 |
107 Object* Object::ToBoolean() { | 107 Object* Object::ToBoolean() { |
108 if (IsTrue()) return this; | 108 if (IsTrue()) return this; |
109 if (IsFalse()) return this; | 109 if (IsFalse()) return this; |
(...skipping 17 matching lines...) Expand all Loading... |
127 } | 127 } |
128 return heap_object->GetHeap()->true_value(); | 128 return heap_object->GetHeap()->true_value(); |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 void Object::Lookup(String* name, LookupResult* result) { | 132 void Object::Lookup(String* name, LookupResult* result) { |
133 Object* holder = NULL; | 133 Object* holder = NULL; |
134 if (IsJSReceiver()) { | 134 if (IsJSReceiver()) { |
135 holder = this; | 135 holder = this; |
136 } else { | 136 } else { |
137 Context* native_context = Isolate::Current()->context()->native_context(); | 137 Context* global_context = Isolate::Current()->context()->global_context(); |
138 if (IsNumber()) { | 138 if (IsNumber()) { |
139 holder = native_context->number_function()->instance_prototype(); | 139 holder = global_context->number_function()->instance_prototype(); |
140 } else if (IsString()) { | 140 } else if (IsString()) { |
141 holder = native_context->string_function()->instance_prototype(); | 141 holder = global_context->string_function()->instance_prototype(); |
142 } else if (IsBoolean()) { | 142 } else if (IsBoolean()) { |
143 holder = native_context->boolean_function()->instance_prototype(); | 143 holder = global_context->boolean_function()->instance_prototype(); |
144 } | 144 } |
145 } | 145 } |
146 ASSERT(holder != NULL); // Cannot handle null or undefined. | 146 ASSERT(holder != NULL); // Cannot handle null or undefined. |
147 JSReceiver::cast(holder)->Lookup(name, result); | 147 JSReceiver::cast(holder)->Lookup(name, result); |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver, | 151 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver, |
152 String* name, | 152 String* name, |
153 PropertyAttributes* attributes) { | 153 PropertyAttributes* attributes) { |
(...skipping 29 matching lines...) Expand all Loading... |
183 Handle<Object> receiver_handle(receiver); | 183 Handle<Object> receiver_handle(receiver); |
184 Handle<Object> args[2] = { name_handle, receiver_handle }; | 184 Handle<Object> args[2] = { name_handle, receiver_handle }; |
185 Handle<Object> error = | 185 Handle<Object> error = |
186 isolate->factory()->NewTypeError("incompatible_method_receiver", | 186 isolate->factory()->NewTypeError("incompatible_method_receiver", |
187 HandleVector(args, | 187 HandleVector(args, |
188 ARRAY_SIZE(args))); | 188 ARRAY_SIZE(args))); |
189 return isolate->Throw(*error); | 189 return isolate->Throw(*error); |
190 } | 190 } |
191 Object* fun_obj = data->getter(); | 191 Object* fun_obj = data->getter(); |
192 v8::AccessorGetter call_fun = v8::ToCData<v8::AccessorGetter>(fun_obj); | 192 v8::AccessorGetter call_fun = v8::ToCData<v8::AccessorGetter>(fun_obj); |
193 if (call_fun == NULL) return isolate->heap()->undefined_value(); | |
194 HandleScope scope(isolate); | 193 HandleScope scope(isolate); |
195 JSObject* self = JSObject::cast(receiver); | 194 JSObject* self = JSObject::cast(receiver); |
196 Handle<String> key(name); | 195 Handle<String> key(name); |
197 LOG(isolate, ApiNamedPropertyAccess("load", self, name)); | 196 LOG(isolate, ApiNamedPropertyAccess("load", self, name)); |
198 CustomArguments args(isolate, data->data(), self, this); | 197 CustomArguments args(isolate, data->data(), self, this); |
199 v8::AccessorInfo info(args.end()); | 198 v8::AccessorInfo info(args.end()); |
200 v8::Handle<v8::Value> result; | 199 v8::Handle<v8::Value> result; |
201 { | 200 { |
202 // Leaving JavaScript. | 201 // Leaving JavaScript. |
203 VMState state(isolate, EXTERNAL); | 202 VMState state(isolate, EXTERNAL); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 : HeapObject::cast(this)->GetHeap(); | 655 : HeapObject::cast(this)->GetHeap(); |
657 Object* holder = this; | 656 Object* holder = this; |
658 | 657 |
659 // Iterate up the prototype chain until an element is found or the null | 658 // Iterate up the prototype chain until an element is found or the null |
660 // prototype is encountered. | 659 // prototype is encountered. |
661 for (holder = this; | 660 for (holder = this; |
662 holder != heap->null_value(); | 661 holder != heap->null_value(); |
663 holder = holder->GetPrototype()) { | 662 holder = holder->GetPrototype()) { |
664 if (!holder->IsJSObject()) { | 663 if (!holder->IsJSObject()) { |
665 Isolate* isolate = heap->isolate(); | 664 Isolate* isolate = heap->isolate(); |
666 Context* native_context = isolate->context()->native_context(); | 665 Context* global_context = isolate->context()->global_context(); |
667 if (holder->IsNumber()) { | 666 if (holder->IsNumber()) { |
668 holder = native_context->number_function()->instance_prototype(); | 667 holder = global_context->number_function()->instance_prototype(); |
669 } else if (holder->IsString()) { | 668 } else if (holder->IsString()) { |
670 holder = native_context->string_function()->instance_prototype(); | 669 holder = global_context->string_function()->instance_prototype(); |
671 } else if (holder->IsBoolean()) { | 670 } else if (holder->IsBoolean()) { |
672 holder = native_context->boolean_function()->instance_prototype(); | 671 holder = global_context->boolean_function()->instance_prototype(); |
673 } else if (holder->IsJSProxy()) { | 672 } else if (holder->IsJSProxy()) { |
674 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index); | 673 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index); |
675 } else { | 674 } else { |
676 // Undefined and null have no indexed properties. | 675 // Undefined and null have no indexed properties. |
677 ASSERT(holder->IsUndefined() || holder->IsNull()); | 676 ASSERT(holder->IsUndefined() || holder->IsNull()); |
678 return heap->undefined_value(); | 677 return heap->undefined_value(); |
679 } | 678 } |
680 } | 679 } |
681 | 680 |
682 // Inline the case for JSObjects. Doing so significantly improves the | 681 // Inline the case for JSObjects. Doing so significantly improves the |
(...skipping 21 matching lines...) Expand all Loading... |
704 } | 703 } |
705 } | 704 } |
706 | 705 |
707 return heap->undefined_value(); | 706 return heap->undefined_value(); |
708 } | 707 } |
709 | 708 |
710 | 709 |
711 Object* Object::GetPrototype() { | 710 Object* Object::GetPrototype() { |
712 if (IsSmi()) { | 711 if (IsSmi()) { |
713 Heap* heap = Isolate::Current()->heap(); | 712 Heap* heap = Isolate::Current()->heap(); |
714 Context* context = heap->isolate()->context()->native_context(); | 713 Context* context = heap->isolate()->context()->global_context(); |
715 return context->number_function()->instance_prototype(); | 714 return context->number_function()->instance_prototype(); |
716 } | 715 } |
717 | 716 |
718 HeapObject* heap_object = HeapObject::cast(this); | 717 HeapObject* heap_object = HeapObject::cast(this); |
719 | 718 |
720 // The object is either a number, a string, a boolean, | 719 // The object is either a number, a string, a boolean, |
721 // a real JS object, or a Harmony proxy. | 720 // a real JS object, or a Harmony proxy. |
722 if (heap_object->IsJSReceiver()) { | 721 if (heap_object->IsJSReceiver()) { |
723 return heap_object->map()->prototype(); | 722 return heap_object->map()->prototype(); |
724 } | 723 } |
725 Heap* heap = heap_object->GetHeap(); | 724 Heap* heap = heap_object->GetHeap(); |
726 Context* context = heap->isolate()->context()->native_context(); | 725 Context* context = heap->isolate()->context()->global_context(); |
727 | 726 |
728 if (heap_object->IsHeapNumber()) { | 727 if (heap_object->IsHeapNumber()) { |
729 return context->number_function()->instance_prototype(); | 728 return context->number_function()->instance_prototype(); |
730 } | 729 } |
731 if (heap_object->IsString()) { | 730 if (heap_object->IsString()) { |
732 return context->string_function()->instance_prototype(); | 731 return context->string_function()->instance_prototype(); |
733 } | 732 } |
734 if (heap_object->IsBoolean()) { | 733 if (heap_object->IsBoolean()) { |
735 return context->boolean_function()->instance_prototype(); | 734 return context->boolean_function()->instance_prototype(); |
736 } else { | 735 } else { |
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 } | 3335 } |
3337 | 3336 |
3338 Heap* current_heap = GetHeap(); | 3337 Heap* current_heap = GetHeap(); |
3339 | 3338 |
3340 // Copy the next enumeration index from instance descriptor. | 3339 // Copy the next enumeration index from instance descriptor. |
3341 int index = map_of_this->instance_descriptors()->NextEnumerationIndex(); | 3340 int index = map_of_this->instance_descriptors()->NextEnumerationIndex(); |
3342 dictionary->SetNextEnumerationIndex(index); | 3341 dictionary->SetNextEnumerationIndex(index); |
3343 | 3342 |
3344 Map* new_map; | 3343 Map* new_map; |
3345 MaybeObject* maybe_map = | 3344 MaybeObject* maybe_map = |
3346 current_heap->isolate()->context()->native_context()-> | 3345 current_heap->isolate()->context()->global_context()-> |
3347 normalized_map_cache()->Get(this, mode); | 3346 normalized_map_cache()->Get(this, mode); |
3348 if (!maybe_map->To(&new_map)) return maybe_map; | 3347 if (!maybe_map->To(&new_map)) return maybe_map; |
3349 ASSERT(new_map->is_dictionary_map()); | 3348 ASSERT(new_map->is_dictionary_map()); |
3350 | 3349 |
3351 // We have now successfully allocated all the necessary objects. | 3350 // We have now successfully allocated all the necessary objects. |
3352 // Changes can now be made with the guarantee that all of them take effect. | 3351 // Changes can now be made with the guarantee that all of them take effect. |
3353 | 3352 |
3354 // Resize the object in the heap if necessary. | 3353 // Resize the object in the heap if necessary. |
3355 int new_instance_size = new_map->instance_size(); | 3354 int new_instance_size = new_map->instance_size(); |
3356 int instance_size_delta = map_of_this->instance_size() - new_instance_size; | 3355 int instance_size_delta = map_of_this->instance_size() - new_instance_size; |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4051 FAST_HOLEY_ELEMENTS; | 4050 FAST_HOLEY_ELEMENTS; |
4052 if (ReferencesObjectFromElements(arguments, kind, obj)) return true; | 4051 if (ReferencesObjectFromElements(arguments, kind, obj)) return true; |
4053 break; | 4052 break; |
4054 } | 4053 } |
4055 } | 4054 } |
4056 | 4055 |
4057 // For functions check the context. | 4056 // For functions check the context. |
4058 if (IsJSFunction()) { | 4057 if (IsJSFunction()) { |
4059 // Get the constructor function for arguments array. | 4058 // Get the constructor function for arguments array. |
4060 JSObject* arguments_boilerplate = | 4059 JSObject* arguments_boilerplate = |
4061 heap->isolate()->context()->native_context()-> | 4060 heap->isolate()->context()->global_context()-> |
4062 arguments_boilerplate(); | 4061 arguments_boilerplate(); |
4063 JSFunction* arguments_function = | 4062 JSFunction* arguments_function = |
4064 JSFunction::cast(arguments_boilerplate->map()->constructor()); | 4063 JSFunction::cast(arguments_boilerplate->map()->constructor()); |
4065 | 4064 |
4066 // Get the context and don't check if it is the native context. | 4065 // Get the context and don't check if it is the global context. |
4067 JSFunction* f = JSFunction::cast(this); | 4066 JSFunction* f = JSFunction::cast(this); |
4068 Context* context = f->context(); | 4067 Context* context = f->context(); |
4069 if (context->IsNativeContext()) { | 4068 if (context->IsGlobalContext()) { |
4070 return false; | 4069 return false; |
4071 } | 4070 } |
4072 | 4071 |
4073 // Check the non-special context slots. | 4072 // Check the non-special context slots. |
4074 for (int i = Context::MIN_CONTEXT_SLOTS; i < context->length(); i++) { | 4073 for (int i = Context::MIN_CONTEXT_SLOTS; i < context->length(); i++) { |
4075 // Only check JS objects. | 4074 // Only check JS objects. |
4076 if (context->get(i)->IsJSObject()) { | 4075 if (context->get(i)->IsJSObject()) { |
4077 JSObject* ctxobj = JSObject::cast(context->get(i)); | 4076 JSObject* ctxobj = JSObject::cast(context->get(i)); |
4078 // If it is an arguments array check the content. | 4077 // If it is an arguments array check the content. |
4079 if (ctxobj->map()->constructor() == arguments_function) { | 4078 if (ctxobj->map()->constructor() == arguments_function) { |
(...skipping 3290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7370 } | 7369 } |
7371 | 7370 |
7372 | 7371 |
7373 void SharedFunctionInfo::ClearOptimizedCodeMap() { | 7372 void SharedFunctionInfo::ClearOptimizedCodeMap() { |
7374 set_optimized_code_map(Smi::FromInt(0)); | 7373 set_optimized_code_map(Smi::FromInt(0)); |
7375 } | 7374 } |
7376 | 7375 |
7377 | 7376 |
7378 void SharedFunctionInfo::AddToOptimizedCodeMap( | 7377 void SharedFunctionInfo::AddToOptimizedCodeMap( |
7379 Handle<SharedFunctionInfo> shared, | 7378 Handle<SharedFunctionInfo> shared, |
7380 Handle<Context> native_context, | 7379 Handle<Context> global_context, |
7381 Handle<Code> code, | 7380 Handle<Code> code, |
7382 Handle<FixedArray> literals) { | 7381 Handle<FixedArray> literals) { |
7383 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); | 7382 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
7384 ASSERT(native_context->IsNativeContext()); | 7383 ASSERT(global_context->IsGlobalContext()); |
7385 STATIC_ASSERT(kEntryLength == 3); | 7384 STATIC_ASSERT(kEntryLength == 3); |
7386 Object* value = shared->optimized_code_map(); | 7385 Object* value = shared->optimized_code_map(); |
7387 Handle<FixedArray> new_code_map; | 7386 Handle<FixedArray> new_code_map; |
7388 if (value->IsSmi()) { | 7387 if (value->IsSmi()) { |
7389 // No optimized code map. | 7388 // No optimized code map. |
7390 ASSERT_EQ(0, Smi::cast(value)->value()); | 7389 ASSERT_EQ(0, Smi::cast(value)->value()); |
7391 // Crate 3 entries per context {context, code, literals}. | 7390 // Crate 3 entries per context {context, code, literals}. |
7392 new_code_map = FACTORY->NewFixedArray(kEntryLength); | 7391 new_code_map = FACTORY->NewFixedArray(kEntryLength); |
7393 new_code_map->set(0, *native_context); | 7392 new_code_map->set(0, *global_context); |
7394 new_code_map->set(1, *code); | 7393 new_code_map->set(1, *code); |
7395 new_code_map->set(2, *literals); | 7394 new_code_map->set(2, *literals); |
7396 } else { | 7395 } else { |
7397 // Copy old map and append one new entry. | 7396 // Copy old map and append one new entry. |
7398 Handle<FixedArray> old_code_map(FixedArray::cast(value)); | 7397 Handle<FixedArray> old_code_map(FixedArray::cast(value)); |
7399 ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*native_context)); | 7398 ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*global_context)); |
7400 int old_length = old_code_map->length(); | 7399 int old_length = old_code_map->length(); |
7401 int new_length = old_length + kEntryLength; | 7400 int new_length = old_length + kEntryLength; |
7402 new_code_map = FACTORY->NewFixedArray(new_length); | 7401 new_code_map = FACTORY->NewFixedArray(new_length); |
7403 old_code_map->CopyTo(0, *new_code_map, 0, old_length); | 7402 old_code_map->CopyTo(0, *new_code_map, 0, old_length); |
7404 new_code_map->set(old_length, *native_context); | 7403 new_code_map->set(old_length, *global_context); |
7405 new_code_map->set(old_length + 1, *code); | 7404 new_code_map->set(old_length + 1, *code); |
7406 new_code_map->set(old_length + 2, *literals); | 7405 new_code_map->set(old_length + 2, *literals); |
7407 } | 7406 } |
7408 #ifdef DEBUG | 7407 #ifdef DEBUG |
7409 for (int i = 0; i < new_code_map->length(); i += kEntryLength) { | 7408 for (int i = 0; i < new_code_map->length(); i += kEntryLength) { |
7410 ASSERT(new_code_map->get(i)->IsNativeContext()); | 7409 ASSERT(new_code_map->get(i)->IsGlobalContext()); |
7411 ASSERT(new_code_map->get(i + 1)->IsCode()); | 7410 ASSERT(new_code_map->get(i + 1)->IsCode()); |
7412 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() == | 7411 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() == |
7413 Code::OPTIMIZED_FUNCTION); | 7412 Code::OPTIMIZED_FUNCTION); |
7414 ASSERT(new_code_map->get(i + 2)->IsFixedArray()); | 7413 ASSERT(new_code_map->get(i + 2)->IsFixedArray()); |
7415 } | 7414 } |
7416 #endif | 7415 #endif |
7417 shared->set_optimized_code_map(*new_code_map); | 7416 shared->set_optimized_code_map(*new_code_map); |
7418 } | 7417 } |
7419 | 7418 |
7420 | 7419 |
7421 void SharedFunctionInfo::InstallFromOptimizedCodeMap(JSFunction* function, | 7420 void SharedFunctionInfo::InstallFromOptimizedCodeMap(JSFunction* function, |
7422 int index) { | 7421 int index) { |
7423 ASSERT(index > 0); | 7422 ASSERT(index > 0); |
7424 ASSERT(optimized_code_map()->IsFixedArray()); | 7423 ASSERT(optimized_code_map()->IsFixedArray()); |
7425 FixedArray* code_map = FixedArray::cast(optimized_code_map()); | 7424 FixedArray* code_map = FixedArray::cast(optimized_code_map()); |
7426 if (!bound()) { | 7425 if (!bound()) { |
7427 FixedArray* cached_literals = FixedArray::cast(code_map->get(index + 1)); | 7426 FixedArray* cached_literals = FixedArray::cast(code_map->get(index + 1)); |
7428 ASSERT(cached_literals != NULL); | 7427 ASSERT(cached_literals != NULL); |
7429 function->set_literals(cached_literals); | 7428 function->set_literals(cached_literals); |
7430 } | 7429 } |
7431 Code* code = Code::cast(code_map->get(index)); | 7430 Code* code = Code::cast(code_map->get(index)); |
7432 ASSERT(code != NULL); | 7431 ASSERT(code != NULL); |
7433 ASSERT(function->context()->native_context() == code_map->get(index - 1)); | 7432 ASSERT(function->context()->global_context() == code_map->get(index - 1)); |
7434 function->ReplaceCode(code); | 7433 function->ReplaceCode(code); |
7435 } | 7434 } |
7436 | 7435 |
7437 | 7436 |
7438 bool JSFunction::CompileLazy(Handle<JSFunction> function, | 7437 bool JSFunction::CompileLazy(Handle<JSFunction> function, |
7439 ClearExceptionFlag flag) { | 7438 ClearExceptionFlag flag) { |
7440 bool result = true; | 7439 bool result = true; |
7441 if (function->shared()->is_compiled()) { | 7440 if (function->shared()->is_compiled()) { |
7442 function->ReplaceCode(function->shared()->code()); | 7441 function->ReplaceCode(function->shared()->code()); |
7443 function->shared()->set_code_age(0); | 7442 function->shared()->set_code_age(0); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7541 // different prototype. | 7540 // different prototype. |
7542 Map* new_map; | 7541 Map* new_map; |
7543 MaybeObject* maybe_new_map = map()->Copy(); | 7542 MaybeObject* maybe_new_map = map()->Copy(); |
7544 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 7543 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
7545 | 7544 |
7546 Heap* heap = new_map->GetHeap(); | 7545 Heap* heap = new_map->GetHeap(); |
7547 set_map(new_map); | 7546 set_map(new_map); |
7548 new_map->set_constructor(value); | 7547 new_map->set_constructor(value); |
7549 new_map->set_non_instance_prototype(true); | 7548 new_map->set_non_instance_prototype(true); |
7550 construct_prototype = | 7549 construct_prototype = |
7551 heap->isolate()->context()->native_context()-> | 7550 heap->isolate()->context()->global_context()-> |
7552 initial_object_prototype(); | 7551 initial_object_prototype(); |
7553 } else { | 7552 } else { |
7554 map()->set_non_instance_prototype(false); | 7553 map()->set_non_instance_prototype(false); |
7555 } | 7554 } |
7556 | 7555 |
7557 return SetInstancePrototype(construct_prototype); | 7556 return SetInstancePrototype(construct_prototype); |
7558 } | 7557 } |
7559 | 7558 |
7560 | 7559 |
7561 Object* JSFunction::RemovePrototype() { | 7560 Object* JSFunction::RemovePrototype() { |
7562 Context* native_context = context()->native_context(); | 7561 Context* global_context = context()->global_context(); |
7563 Map* no_prototype_map = shared()->is_classic_mode() | 7562 Map* no_prototype_map = shared()->is_classic_mode() |
7564 ? native_context->function_without_prototype_map() | 7563 ? global_context->function_without_prototype_map() |
7565 : native_context->strict_mode_function_without_prototype_map(); | 7564 : global_context->strict_mode_function_without_prototype_map(); |
7566 | 7565 |
7567 if (map() == no_prototype_map) { | 7566 if (map() == no_prototype_map) { |
7568 // Be idempotent. | 7567 // Be idempotent. |
7569 return this; | 7568 return this; |
7570 } | 7569 } |
7571 | 7570 |
7572 ASSERT(map() == (shared()->is_classic_mode() | 7571 ASSERT(map() == (shared()->is_classic_mode() |
7573 ? native_context->function_map() | 7572 ? global_context->function_map() |
7574 : native_context->strict_mode_function_map())); | 7573 : global_context->strict_mode_function_map())); |
7575 | 7574 |
7576 set_map(no_prototype_map); | 7575 set_map(no_prototype_map); |
7577 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value()); | 7576 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value()); |
7578 return this; | 7577 return this; |
7579 } | 7578 } |
7580 | 7579 |
7581 | 7580 |
7582 Object* JSFunction::SetInstanceClassName(String* name) { | 7581 Object* JSFunction::SetInstanceClassName(String* name) { |
7583 shared()->set_instance_class_name(name); | 7582 shared()->set_instance_class_name(name); |
7584 return this; | 7583 return this; |
7585 } | 7584 } |
7586 | 7585 |
7587 | 7586 |
7588 void JSFunction::PrintName(FILE* out) { | 7587 void JSFunction::PrintName(FILE* out) { |
7589 SmartArrayPointer<char> name = shared()->DebugName()->ToCString(); | 7588 SmartArrayPointer<char> name = shared()->DebugName()->ToCString(); |
7590 PrintF(out, "%s", *name); | 7589 PrintF(out, "%s", *name); |
7591 } | 7590 } |
7592 | 7591 |
7593 | 7592 |
7594 Context* JSFunction::NativeContextFromLiterals(FixedArray* literals) { | 7593 Context* JSFunction::GlobalContextFromLiterals(FixedArray* literals) { |
7595 return Context::cast(literals->get(JSFunction::kLiteralNativeContextIndex)); | 7594 return Context::cast(literals->get(JSFunction::kLiteralGlobalContextIndex)); |
7596 } | 7595 } |
7597 | 7596 |
7598 | 7597 |
7599 MaybeObject* Oddball::Initialize(const char* to_string, | 7598 MaybeObject* Oddball::Initialize(const char* to_string, |
7600 Object* to_number, | 7599 Object* to_number, |
7601 byte kind) { | 7600 byte kind) { |
7602 String* symbol; | 7601 String* symbol; |
7603 { MaybeObject* maybe_symbol = | 7602 { MaybeObject* maybe_symbol = |
7604 Isolate::Current()->heap()->LookupAsciiSymbol(to_string); | 7603 Isolate::Current()->heap()->LookupAsciiSymbol(to_string); |
7605 if (!maybe_symbol->To(&symbol)) return maybe_symbol; | 7604 if (!maybe_symbol->To(&symbol)) return maybe_symbol; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7983 // Resize the initial map and all maps in its transition tree. | 7982 // Resize the initial map and all maps in its transition tree. |
7984 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); | 7983 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); |
7985 | 7984 |
7986 // Give the correct expected_nof_properties to initial maps created later. | 7985 // Give the correct expected_nof_properties to initial maps created later. |
7987 ASSERT(expected_nof_properties() >= slack); | 7986 ASSERT(expected_nof_properties() >= slack); |
7988 set_expected_nof_properties(expected_nof_properties() - slack); | 7987 set_expected_nof_properties(expected_nof_properties() - slack); |
7989 } | 7988 } |
7990 } | 7989 } |
7991 | 7990 |
7992 | 7991 |
7993 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context) { | 7992 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* global_context) { |
7994 ASSERT(native_context->IsNativeContext()); | 7993 ASSERT(global_context->IsGlobalContext()); |
7995 if (!FLAG_cache_optimized_code) return -1; | 7994 if (!FLAG_cache_optimized_code) return -1; |
7996 Object* value = optimized_code_map(); | 7995 Object* value = optimized_code_map(); |
7997 if (!value->IsSmi()) { | 7996 if (!value->IsSmi()) { |
7998 FixedArray* optimized_code_map = FixedArray::cast(value); | 7997 FixedArray* optimized_code_map = FixedArray::cast(value); |
7999 int length = optimized_code_map->length(); | 7998 int length = optimized_code_map->length(); |
8000 for (int i = 0; i < length; i += 3) { | 7999 for (int i = 0; i < length; i += 3) { |
8001 if (optimized_code_map->get(i) == native_context) { | 8000 if (optimized_code_map->get(i) == global_context) { |
8002 return i + 1; | 8001 return i + 1; |
8003 } | 8002 } |
8004 } | 8003 } |
8005 } | 8004 } |
8006 return -1; | 8005 return -1; |
8007 } | 8006 } |
8008 | 8007 |
8009 | 8008 |
8010 #define DECLARE_TAG(ignore1, name, ignore2) name, | 8009 #define DECLARE_TAG(ignore1, name, ignore2) name, |
8011 const char* const VisitorSynchronization::kTags[ | 8010 const char* const VisitorSynchronization::kTags[ |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8308 int function_id = iterator.Next(); | 8307 int function_id = iterator.Next(); |
8309 JSFunction* function = | 8308 JSFunction* function = |
8310 JSFunction::cast(LiteralArray()->get(function_id)); | 8309 JSFunction::cast(LiteralArray()->get(function_id)); |
8311 unsigned height = iterator.Next(); | 8310 unsigned height = iterator.Next(); |
8312 PrintF(out, "{function="); | 8311 PrintF(out, "{function="); |
8313 function->PrintName(out); | 8312 function->PrintName(out); |
8314 PrintF(out, ", height=%u}", height); | 8313 PrintF(out, ", height=%u}", height); |
8315 break; | 8314 break; |
8316 } | 8315 } |
8317 | 8316 |
8318 case Translation::SETTER_STUB_FRAME: { | |
8319 int function_id = iterator.Next(); | |
8320 JSFunction* function = | |
8321 JSFunction::cast(LiteralArray()->get(function_id)); | |
8322 PrintF(out, "{function="); | |
8323 function->PrintName(out); | |
8324 PrintF(out, "}"); | |
8325 break; | |
8326 } | |
8327 | |
8328 case Translation::DUPLICATE: | 8317 case Translation::DUPLICATE: |
8329 break; | 8318 break; |
8330 | 8319 |
8331 case Translation::REGISTER: { | 8320 case Translation::REGISTER: { |
8332 int reg_code = iterator.Next(); | 8321 int reg_code = iterator.Next(); |
8333 PrintF(out, "{input=%s}", converter.NameOfCPURegister(reg_code)); | 8322 PrintF(out, "{input=%s}", converter.NameOfCPURegister(reg_code)); |
8334 break; | 8323 break; |
8335 } | 8324 } |
8336 | 8325 |
8337 case Translation::INT32_REGISTER: { | 8326 case Translation::INT32_REGISTER: { |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9123 uint32_t index, | 9112 uint32_t index, |
9124 Object* holder) { | 9113 Object* holder) { |
9125 Isolate* isolate = GetIsolate(); | 9114 Isolate* isolate = GetIsolate(); |
9126 ASSERT(!structure->IsForeign()); | 9115 ASSERT(!structure->IsForeign()); |
9127 | 9116 |
9128 // api style callbacks. | 9117 // api style callbacks. |
9129 if (structure->IsAccessorInfo()) { | 9118 if (structure->IsAccessorInfo()) { |
9130 Handle<AccessorInfo> data(AccessorInfo::cast(structure)); | 9119 Handle<AccessorInfo> data(AccessorInfo::cast(structure)); |
9131 Object* fun_obj = data->getter(); | 9120 Object* fun_obj = data->getter(); |
9132 v8::AccessorGetter call_fun = v8::ToCData<v8::AccessorGetter>(fun_obj); | 9121 v8::AccessorGetter call_fun = v8::ToCData<v8::AccessorGetter>(fun_obj); |
9133 if (call_fun == NULL) return isolate->heap()->undefined_value(); | |
9134 HandleScope scope(isolate); | 9122 HandleScope scope(isolate); |
9135 Handle<JSObject> self(JSObject::cast(receiver)); | 9123 Handle<JSObject> self(JSObject::cast(receiver)); |
9136 Handle<JSObject> holder_handle(JSObject::cast(holder)); | 9124 Handle<JSObject> holder_handle(JSObject::cast(holder)); |
9137 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); | 9125 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); |
9138 Handle<String> key = isolate->factory()->NumberToString(number); | 9126 Handle<String> key = isolate->factory()->NumberToString(number); |
9139 LOG(isolate, ApiNamedPropertyAccess("load", *self, *key)); | 9127 LOG(isolate, ApiNamedPropertyAccess("load", *self, *key)); |
9140 CustomArguments args(isolate, data->data(), *self, *holder_handle); | 9128 CustomArguments args(isolate, data->data(), *self, *holder_handle); |
9141 v8::AccessorInfo info(args.end()); | 9129 v8::AccessorInfo info(args.end()); |
9142 v8::Handle<v8::Value> result; | 9130 v8::Handle<v8::Value> result; |
9143 { | 9131 { |
(...skipping 4023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13167 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13155 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13168 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13156 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13169 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13157 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13170 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13158 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13171 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13159 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13172 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13160 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13173 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13161 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13174 } | 13162 } |
13175 | 13163 |
13176 } } // namespace v8::internal | 13164 } } // namespace v8::internal |
OLD | NEW |