OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include "bindings/v8/ScriptController.h" | 34 #include "bindings/v8/ScriptController.h" |
35 #include "bindings/v8/ScriptSourceCode.h" | 35 #include "bindings/v8/ScriptSourceCode.h" |
36 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
37 #include "bindings/v8/V8GCController.h" | 37 #include "bindings/v8/V8GCController.h" |
38 #include "bindings/v8/V8ScriptRunner.h" | 38 #include "bindings/v8/V8ScriptRunner.h" |
39 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
40 #include "core/dom/ScriptExecutionContext.h" | 40 #include "core/dom/ScriptExecutionContext.h" |
41 #include "core/page/Frame.h" | 41 #include "core/page/Frame.h" |
42 #include "core/platform/chromium/TraceEvent.h" | 42 #include "core/platform/chromium/TraceEvent.h" |
43 #include "core/workers/WorkerContext.h" | 43 #include "core/workers/WorkerGlobalScope.h" |
44 #include "core/workers/WorkerThread.h" | 44 #include "core/workers/WorkerThread.h" |
45 | 45 |
46 namespace WebCore { | 46 namespace WebCore { |
47 | 47 |
48 ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8:
:Function> function, int argc, v8::Handle<v8::Value> argv[], v8::Isolate* isolat
e) | 48 ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8:
:Function> function, int argc, v8::Handle<v8::Value> argv[], v8::Isolate* isolat
e) |
49 : m_context(context) | 49 : m_context(context) |
50 , m_function(function) | 50 , m_function(function) |
51 , m_code(String(), KURL(), TextPosition::belowRangePosition()) | 51 , m_code(String(), KURL(), TextPosition::belowRangePosition()) |
52 , m_isolate(isolate) | 52 , m_isolate(isolate) |
53 { | 53 { |
(...skipping 18 matching lines...) Expand all Loading... |
72 void ScheduledAction::execute(ScriptExecutionContext* context) | 72 void ScheduledAction::execute(ScriptExecutionContext* context) |
73 { | 73 { |
74 if (context->isDocument()) { | 74 if (context->isDocument()) { |
75 Frame* frame = toDocument(context)->frame(); | 75 Frame* frame = toDocument(context)->frame(); |
76 if (!frame) | 76 if (!frame) |
77 return; | 77 return; |
78 if (!frame->script()->canExecuteScripts(AboutToExecuteScript)) | 78 if (!frame->script()->canExecuteScripts(AboutToExecuteScript)) |
79 return; | 79 return; |
80 execute(frame); | 80 execute(frame); |
81 } else { | 81 } else { |
82 ASSERT(context->isWorkerContext()); | 82 ASSERT(context->isWorkerGlobalScope()); |
83 execute(static_cast<WorkerContext*>(context)); | 83 execute(static_cast<WorkerGlobalScope*>(context)); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void ScheduledAction::execute(Frame* frame) | 87 void ScheduledAction::execute(Frame* frame) |
88 { | 88 { |
89 v8::HandleScope handleScope(m_isolate); | 89 v8::HandleScope handleScope(m_isolate); |
90 | 90 |
91 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); | 91 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); |
92 if (context.IsEmpty()) | 92 if (context.IsEmpty()) |
93 return; | 93 return; |
94 v8::Context::Scope scope(context); | 94 v8::Context::Scope scope(context); |
95 | 95 |
96 TRACE_EVENT0("v8", "ScheduledAction::execute"); | 96 TRACE_EVENT0("v8", "ScheduledAction::execute"); |
97 | 97 |
98 if (!m_function.isEmpty()) { | 98 if (!m_function.isEmpty()) { |
99 Vector<v8::Handle<v8::Value> > args; | 99 Vector<v8::Handle<v8::Value> > args; |
100 createLocalHandlesForArgs(&args); | 100 createLocalHandlesForArgs(&args); |
101 frame->script()->callFunction(m_function.newLocal(m_isolate), context->G
lobal(), args.size(), args.data()); | 101 frame->script()->callFunction(m_function.newLocal(m_isolate), context->G
lobal(), args.size(), args.data()); |
102 } else | 102 } else |
103 frame->script()->compileAndRunScript(m_code); | 103 frame->script()->compileAndRunScript(m_code); |
104 | 104 |
105 // The frame might be invalid at this point because JavaScript could have re
leased it. | 105 // The frame might be invalid at this point because JavaScript could have re
leased it. |
106 } | 106 } |
107 | 107 |
108 void ScheduledAction::execute(WorkerContext* worker) | 108 void ScheduledAction::execute(WorkerGlobalScope* worker) |
109 { | 109 { |
110 ASSERT(worker->thread()->isCurrentThread()); | 110 ASSERT(worker->thread()->isCurrentThread()); |
111 v8::HandleScope handleScope(m_isolate); | 111 v8::HandleScope handleScope(m_isolate); |
112 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); | 112 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); |
113 ASSERT(!context.IsEmpty()); | 113 ASSERT(!context.IsEmpty()); |
114 v8::Context::Scope scope(context); | 114 v8::Context::Scope scope(context); |
115 if (!m_function.isEmpty()) { | 115 if (!m_function.isEmpty()) { |
116 Vector<v8::Handle<v8::Value> > args; | 116 Vector<v8::Handle<v8::Value> > args; |
117 createLocalHandlesForArgs(&args); | 117 createLocalHandlesForArgs(&args); |
118 V8ScriptRunner::callFunction(m_function.newLocal(m_isolate), worker, con
text->Global(), args.size(), args.data()); | 118 V8ScriptRunner::callFunction(m_function.newLocal(m_isolate), worker, con
text->Global(), args.size(), args.data()); |
119 } else | 119 } else |
120 worker->script()->evaluate(m_code); | 120 worker->script()->evaluate(m_code); |
121 } | 121 } |
122 | 122 |
123 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Handle<v8::Value> >*
handles) | 123 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Handle<v8::Value> >*
handles) |
124 { | 124 { |
125 handles->reserveCapacity(m_args.size()); | 125 handles->reserveCapacity(m_args.size()); |
126 for (size_t i = 0; i < m_args.size(); ++i) | 126 for (size_t i = 0; i < m_args.size(); ++i) |
127 handles->append(m_args[i].newLocal(m_isolate)); | 127 handles->append(m_args[i].newLocal(m_isolate)); |
128 } | 128 } |
129 | 129 |
130 } // namespace WebCore | 130 } // namespace WebCore |
OLD | NEW |