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 28 matching lines...) Expand all Loading... |
39 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
40 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
41 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
42 #include "core/workers/WorkerGlobalScope.h" | 42 #include "core/workers/WorkerGlobalScope.h" |
43 #include "core/workers/WorkerThread.h" | 43 #include "core/workers/WorkerThread.h" |
44 #include "platform/Logging.h" | 44 #include "platform/Logging.h" |
45 #include "platform/TraceEvent.h" | 45 #include "platform/TraceEvent.h" |
46 | 46 |
47 namespace blink { | 47 namespace blink { |
48 | 48 |
49 ScheduledAction::ScheduledAction(ScriptState* scriptState, v8::Handle<v8::Functi
on> function, int argc, v8::Handle<v8::Value> argv[], v8::Isolate* isolate) | 49 PassOwnPtr<ScheduledAction> ScheduledAction::create(ScriptState* scriptState, co
nst ScriptValue& handler, const Vector<ScriptValue>& arguments) |
50 : m_scriptState(scriptState) | |
51 , m_function(isolate, function) | |
52 , m_info(isolate) | |
53 , m_code(String(), KURL(), TextPosition::belowRangePosition()) | |
54 { | 50 { |
55 m_info.ReserveCapacity(argc); | 51 ASSERT(handler.isFunction()); |
56 for (int i = 0; i < argc; ++i) | 52 return adoptPtr(new ScheduledAction(scriptState, handler, arguments)); |
57 m_info.Append(argv[i]); | |
58 } | 53 } |
59 | 54 |
60 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code, c
onst KURL& url, v8::Isolate* isolate) | 55 PassOwnPtr<ScheduledAction> ScheduledAction::create(ScriptState* scriptState, co
nst String& handler) |
61 : m_scriptState(scriptState) | |
62 , m_info(isolate) | |
63 , m_code(code, url) | |
64 { | 56 { |
| 57 return adoptPtr(new ScheduledAction(scriptState, handler)); |
65 } | 58 } |
66 | 59 |
67 ScheduledAction::~ScheduledAction() | 60 ScheduledAction::~ScheduledAction() |
68 { | 61 { |
69 } | 62 } |
70 | 63 |
71 void ScheduledAction::execute(ExecutionContext* context) | 64 void ScheduledAction::execute(ExecutionContext* context) |
72 { | 65 { |
73 if (context->isDocument()) { | 66 if (context->isDocument()) { |
74 LocalFrame* frame = toDocument(context)->frame(); | 67 LocalFrame* frame = toDocument(context)->frame(); |
75 if (!frame) { | 68 if (!frame) { |
76 WTF_LOG(Timers, "ScheduledAction::execute %p: no frame", this); | 69 WTF_LOG(Timers, "ScheduledAction::execute %p: no frame", this); |
77 return; | 70 return; |
78 } | 71 } |
79 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) { | 72 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) { |
80 WTF_LOG(Timers, "ScheduledAction::execute %p: frame can not execute
scripts", this); | 73 WTF_LOG(Timers, "ScheduledAction::execute %p: frame can not execute
scripts", this); |
81 return; | 74 return; |
82 } | 75 } |
83 execute(frame); | 76 execute(frame); |
84 } else { | 77 } else { |
85 WTF_LOG(Timers, "ScheduledAction::execute %p: worker scope", this); | 78 WTF_LOG(Timers, "ScheduledAction::execute %p: worker scope", this); |
86 execute(toWorkerGlobalScope(context)); | 79 execute(toWorkerGlobalScope(context)); |
87 } | 80 } |
88 } | 81 } |
89 | 82 |
| 83 ScheduledAction::ScheduledAction(ScriptState* scriptState, const ScriptValue& fu
nction, const Vector<ScriptValue>& arguments) |
| 84 : m_scriptState(scriptState) |
| 85 , m_info(scriptState->isolate()) |
| 86 , m_code(String(), KURL(), TextPosition::belowRangePosition()) |
| 87 { |
| 88 ASSERT(function.isFunction()); |
| 89 m_function.set(scriptState->isolate(), v8::Handle<v8::Function>::Cast(functi
on.v8Value())); |
| 90 m_info.ReserveCapacity(arguments.size()); |
| 91 for (const ScriptValue& argument : arguments) |
| 92 m_info.Append(argument.v8Value()); |
| 93 } |
| 94 |
| 95 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code) |
| 96 : m_scriptState(scriptState) |
| 97 , m_info(scriptState->isolate()) |
| 98 , m_code(code, KURL()) |
| 99 { |
| 100 } |
| 101 |
90 void ScheduledAction::execute(LocalFrame* frame) | 102 void ScheduledAction::execute(LocalFrame* frame) |
91 { | 103 { |
92 if (!m_scriptState->contextIsValid()) { | 104 if (!m_scriptState->contextIsValid()) { |
93 WTF_LOG(Timers, "ScheduledAction::execute %p: context is empty", this); | 105 WTF_LOG(Timers, "ScheduledAction::execute %p: context is empty", this); |
94 return; | 106 return; |
95 } | 107 } |
96 | 108 |
97 TRACE_EVENT0("v8", "ScheduledAction::execute"); | 109 TRACE_EVENT0("v8", "ScheduledAction::execute"); |
98 ScriptState::Scope scope(m_scriptState.get()); | 110 ScriptState::Scope scope(m_scriptState.get()); |
99 if (!m_function.isEmpty()) { | 111 if (!m_function.isEmpty()) { |
(...skipping 24 matching lines...) Expand all Loading... |
124 } | 136 } |
125 | 137 |
126 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Handle<v8::Value> >*
handles) | 138 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Handle<v8::Value> >*
handles) |
127 { | 139 { |
128 handles->reserveCapacity(m_info.Size()); | 140 handles->reserveCapacity(m_info.Size()); |
129 for (size_t i = 0; i < m_info.Size(); ++i) | 141 for (size_t i = 0; i < m_info.Size(); ++i) |
130 handles->append(m_info.Get(i)); | 142 handles->append(m_info.Get(i)); |
131 } | 143 } |
132 | 144 |
133 } // namespace blink | 145 } // namespace blink |
OLD | NEW |