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 10365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10376 Handle<JSFunction> constructor = isolate->script_function(); | 10376 Handle<JSFunction> constructor = isolate->script_function(); |
10377 Handle<JSValue> result = | 10377 Handle<JSValue> result = |
10378 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 10378 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
10379 result->set_value(*script); | 10379 result->set_value(*script); |
10380 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); | 10380 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); |
10381 script->set_wrapper(*cell); | 10381 script->set_wrapper(*cell); |
10382 return result; | 10382 return result; |
10383 } | 10383 } |
10384 | 10384 |
10385 | 10385 |
| 10386 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |
| 10387 FunctionLiteral* fun) { |
| 10388 if (shared_function_infos()->IsWeakFixedArray()) { |
| 10389 WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos()); |
| 10390 for (int i = 0; i < array->Length(); i++) { |
| 10391 Object* obj = array->Get(i); |
| 10392 if (!obj->IsSharedFunctionInfo()) continue; |
| 10393 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
| 10394 if (fun->function_token_position() == shared->function_token_position() && |
| 10395 fun->start_position() == shared->start_position()) { |
| 10396 return Handle<SharedFunctionInfo>(shared); |
| 10397 } |
| 10398 } |
| 10399 } |
| 10400 return MaybeHandle<SharedFunctionInfo>(); |
| 10401 } |
| 10402 |
| 10403 |
| 10404 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
| 10405 Handle<Object> script_object) { |
| 10406 if (shared->script() == *script_object) return; |
| 10407 // Remove shared function info from old script's list. |
| 10408 if (shared->script()->IsScript()) { |
| 10409 Script* old_script = Script::cast(shared->script()); |
| 10410 if (old_script->shared_function_infos()->IsWeakFixedArray()) { |
| 10411 WeakFixedArray* list = |
| 10412 WeakFixedArray::cast(old_script->shared_function_infos()); |
| 10413 list->Remove(shared); |
| 10414 } |
| 10415 } |
| 10416 // Add shared function info to new script's list. |
| 10417 if (script_object->IsScript()) { |
| 10418 Handle<Script> script = Handle<Script>::cast(script_object); |
| 10419 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate()); |
| 10420 #ifdef DEBUG |
| 10421 bool found = false; |
| 10422 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAddIfNotFound, |
| 10423 &found); |
| 10424 CHECK(!found); |
| 10425 #else |
| 10426 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAlwaysAdd); |
| 10427 #endif // DEBUG |
| 10428 script->set_shared_function_infos(*list); |
| 10429 } |
| 10430 // Finally set new script. |
| 10431 shared->set_script(*script_object); |
| 10432 } |
| 10433 |
| 10434 |
10386 String* SharedFunctionInfo::DebugName() { | 10435 String* SharedFunctionInfo::DebugName() { |
10387 Object* n = name(); | 10436 Object* n = name(); |
10388 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); | 10437 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); |
10389 return String::cast(n); | 10438 return String::cast(n); |
10390 } | 10439 } |
10391 | 10440 |
10392 | 10441 |
10393 bool SharedFunctionInfo::HasSourceCode() const { | 10442 bool SharedFunctionInfo::HasSourceCode() const { |
10394 return !script()->IsUndefined() && | 10443 return !script()->IsUndefined() && |
10395 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); | 10444 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); |
(...skipping 5710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16106 Handle<Object> new_value) { | 16155 Handle<Object> new_value) { |
16107 if (cell->value() != *new_value) { | 16156 if (cell->value() != *new_value) { |
16108 cell->set_value(*new_value); | 16157 cell->set_value(*new_value); |
16109 Isolate* isolate = cell->GetIsolate(); | 16158 Isolate* isolate = cell->GetIsolate(); |
16110 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16159 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16111 isolate, DependentCode::kPropertyCellChangedGroup); | 16160 isolate, DependentCode::kPropertyCellChangedGroup); |
16112 } | 16161 } |
16113 } | 16162 } |
16114 } // namespace internal | 16163 } // namespace internal |
16115 } // namespace v8 | 16164 } // namespace v8 |
OLD | NEW |