| 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 10386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10397 Handle<JSFunction> constructor = isolate->script_function(); | 10397 Handle<JSFunction> constructor = isolate->script_function(); |
| 10398 Handle<JSValue> result = | 10398 Handle<JSValue> result = |
| 10399 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 10399 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
| 10400 result->set_value(*script); | 10400 result->set_value(*script); |
| 10401 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); | 10401 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); |
| 10402 script->set_wrapper(*cell); | 10402 script->set_wrapper(*cell); |
| 10403 return result; | 10403 return result; |
| 10404 } | 10404 } |
| 10405 | 10405 |
| 10406 | 10406 |
| 10407 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( | |
| 10408 FunctionLiteral* fun) { | |
| 10409 if (shared_function_infos()->IsWeakFixedArray()) { | |
| 10410 WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos()); | |
| 10411 for (int i = 0; i < array->Length(); i++) { | |
| 10412 Object* obj = array->Get(i); | |
| 10413 if (!obj->IsSharedFunctionInfo()) continue; | |
| 10414 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | |
| 10415 if (fun->function_token_position() == shared->function_token_position() && | |
| 10416 fun->start_position() == shared->start_position()) { | |
| 10417 return Handle<SharedFunctionInfo>(shared); | |
| 10418 } | |
| 10419 } | |
| 10420 } | |
| 10421 return MaybeHandle<SharedFunctionInfo>(); | |
| 10422 } | |
| 10423 | |
| 10424 | |
| 10425 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, | |
| 10426 Handle<Object> script_object) { | |
| 10427 if (shared->script() == *script_object) return; | |
| 10428 // Remove shared function info from old script's list. | |
| 10429 if (shared->script()->IsScript()) { | |
| 10430 Script* old_script = Script::cast(shared->script()); | |
| 10431 if (old_script->shared_function_infos()->IsWeakFixedArray()) { | |
| 10432 WeakFixedArray* list = | |
| 10433 WeakFixedArray::cast(old_script->shared_function_infos()); | |
| 10434 list->Remove(shared); | |
| 10435 } | |
| 10436 } | |
| 10437 // Add shared function info to new script's list. | |
| 10438 if (script_object->IsScript()) { | |
| 10439 Handle<Script> script = Handle<Script>::cast(script_object); | |
| 10440 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate()); | |
| 10441 #ifdef DEBUG | |
| 10442 bool found = false; | |
| 10443 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAddIfNotFound, | |
| 10444 &found); | |
| 10445 CHECK(!found); | |
| 10446 #else | |
| 10447 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAlwaysAdd); | |
| 10448 #endif // DEBUG | |
| 10449 script->set_shared_function_infos(*list); | |
| 10450 } | |
| 10451 // Finally set new script. | |
| 10452 shared->set_script(*script_object); | |
| 10453 } | |
| 10454 | |
| 10455 | |
| 10456 String* SharedFunctionInfo::DebugName() { | 10407 String* SharedFunctionInfo::DebugName() { |
| 10457 Object* n = name(); | 10408 Object* n = name(); |
| 10458 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); | 10409 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); |
| 10459 return String::cast(n); | 10410 return String::cast(n); |
| 10460 } | 10411 } |
| 10461 | 10412 |
| 10462 | 10413 |
| 10463 bool SharedFunctionInfo::HasSourceCode() const { | 10414 bool SharedFunctionInfo::HasSourceCode() const { |
| 10464 return !script()->IsUndefined() && | 10415 return !script()->IsUndefined() && |
| 10465 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); | 10416 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); |
| (...skipping 5821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16287 Handle<Object> new_value) { | 16238 Handle<Object> new_value) { |
| 16288 if (cell->value() != *new_value) { | 16239 if (cell->value() != *new_value) { |
| 16289 cell->set_value(*new_value); | 16240 cell->set_value(*new_value); |
| 16290 Isolate* isolate = cell->GetIsolate(); | 16241 Isolate* isolate = cell->GetIsolate(); |
| 16291 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16242 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 16292 isolate, DependentCode::kPropertyCellChangedGroup); | 16243 isolate, DependentCode::kPropertyCellChangedGroup); |
| 16293 } | 16244 } |
| 16294 } | 16245 } |
| 16295 } // namespace internal | 16246 } // namespace internal |
| 16296 } // namespace v8 | 16247 } // namespace v8 |
| OLD | NEW |