OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 10431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10442 Handle<JSFunction> constructor = isolate->script_function(); | 10442 Handle<JSFunction> constructor = isolate->script_function(); |
10443 Handle<JSValue> result = | 10443 Handle<JSValue> result = |
10444 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 10444 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
10445 result->set_value(*script); | 10445 result->set_value(*script); |
10446 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); | 10446 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); |
10447 script->set_wrapper(*cell); | 10447 script->set_wrapper(*cell); |
10448 return result; | 10448 return result; |
10449 } | 10449 } |
10450 | 10450 |
10451 | 10451 |
| 10452 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |
| 10453 FunctionLiteral* fun) { |
| 10454 if (shared_function_infos()->IsWeakFixedArray()) { |
| 10455 WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos()); |
| 10456 for (int i = 0; i < array->Length(); i++) { |
| 10457 Object* obj = array->Get(i); |
| 10458 if (!obj->IsSharedFunctionInfo()) continue; |
| 10459 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
| 10460 if (fun->function_token_position() == shared->function_token_position() && |
| 10461 fun->start_position() == shared->start_position() && |
| 10462 fun->end_position() == shared->end_position()) { |
| 10463 return Handle<SharedFunctionInfo>(shared); |
| 10464 } |
| 10465 } |
| 10466 } |
| 10467 return MaybeHandle<SharedFunctionInfo>(); |
| 10468 } |
| 10469 |
| 10470 |
| 10471 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
| 10472 Handle<Object> script_object) { |
| 10473 if (shared->script() == *script_object) return; |
| 10474 // Remove shared function info from old script's list. |
| 10475 if (shared->script()->IsScript()) { |
| 10476 Script* old_script = Script::cast(shared->script()); |
| 10477 if (old_script->shared_function_infos()->IsWeakFixedArray()) { |
| 10478 WeakFixedArray* list = |
| 10479 WeakFixedArray::cast(old_script->shared_function_infos()); |
| 10480 list->Remove(shared); |
| 10481 } |
| 10482 } |
| 10483 // Add shared function info to new script's list. |
| 10484 if (script_object->IsScript()) { |
| 10485 Handle<Script> script = Handle<Script>::cast(script_object); |
| 10486 bool found = false; |
| 10487 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate()); |
| 10488 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAddIfNotFound, |
| 10489 &found); |
| 10490 CHECK(!found); |
| 10491 script->set_shared_function_infos(*list); |
| 10492 } |
| 10493 // Finally set new script. |
| 10494 shared->set_script(*script_object); |
| 10495 } |
| 10496 |
| 10497 |
10452 String* SharedFunctionInfo::DebugName() { | 10498 String* SharedFunctionInfo::DebugName() { |
10453 Object* n = name(); | 10499 Object* n = name(); |
10454 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); | 10500 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); |
10455 return String::cast(n); | 10501 return String::cast(n); |
10456 } | 10502 } |
10457 | 10503 |
10458 | 10504 |
10459 bool SharedFunctionInfo::HasSourceCode() const { | 10505 bool SharedFunctionInfo::HasSourceCode() const { |
10460 return !script()->IsUndefined() && | 10506 return !script()->IsUndefined() && |
10461 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); | 10507 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); |
(...skipping 6198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16660 Handle<Object> new_value) { | 16706 Handle<Object> new_value) { |
16661 if (cell->value() != *new_value) { | 16707 if (cell->value() != *new_value) { |
16662 cell->set_value(*new_value); | 16708 cell->set_value(*new_value); |
16663 Isolate* isolate = cell->GetIsolate(); | 16709 Isolate* isolate = cell->GetIsolate(); |
16664 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16710 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16665 isolate, DependentCode::kPropertyCellChangedGroup); | 16711 isolate, DependentCode::kPropertyCellChangedGroup); |
16666 } | 16712 } |
16667 } | 16713 } |
16668 } // namespace internal | 16714 } // namespace internal |
16669 } // namespace v8 | 16715 } // namespace v8 |
OLD | NEW |