// traversals might be required rendering this operation as a rather slow
// operation. However for setting break points which is normally done through
// some kind of user interaction the performance is not crucial.
-static Handle<Object> Runtime_GetScriptFromScriptName(
- Handle<String> script_name) {
- // Scan the heap for Script objects to find the script with the requested
- // script data.
- Handle<Script> script;
- Factory* factory = script_name->GetIsolate()->factory();
- Heap* heap = script_name->GetHeap();
- HeapIterator iterator(heap);
- HeapObject* obj = NULL;
- while (script.is_null() && ((obj = iterator.next()) != NULL)) {
- // If a script is found check if it has the script data requested.
- if (obj->IsScript()) {
- if (Script::cast(obj)->name()->IsString()) {
- if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) {
- script = Handle<Script>(Script::cast(obj));
- }
- }
- }
- }
-
- // If no script with the requested script data is found return undefined.
- if (script.is_null()) return factory->undefined_value();
-
- // Return the script found.
- return Script::GetWrapper(script);
-}
-
-
-// Get the script object from script data. NOTE: Regarding performance
-// see the NOTE for GetScriptFromScriptData.
-// args[0]: script data for the script to find the source for
RUNTIME_FUNCTION(Runtime_GetScript) {
HandleScope scope(isolate);
-
DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(String, script_name, 0);
- CONVERT_ARG_CHECKED(String, script_name, 0);
+ Handle<Script> found;
+ Heap* heap = isolate->heap();
+ {
+ HeapIterator iterator(heap);
+ HeapObject* obj = NULL;
+ while ((obj = iterator.next()) != NULL) {
+ if (!obj->IsScript()) continue;
+ Script* script = Script::cast(obj);
+ if (!script->name()->IsString()) continue;
+ String* name = String::cast(script->name());
+ if (name->Equals(*script_name)) {
+ found = Handle<Script>(script, isolate);
+ break;
+ }
+ }
+ }
- // Find the requested script.
- Handle<Object> result =
- Runtime_GetScriptFromScriptName(Handle<String>(script_name));
- return *result;
+ if (found.is_null()) return heap->undefined_value();
+ return *Script::GetWrapper(found);
}