| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 ScheduledAction::~ScheduledAction() | 64 ScheduledAction::~ScheduledAction() |
| 65 { | 65 { |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ScheduledAction::execute(ExecutionContext* context) | 68 void ScheduledAction::execute(ExecutionContext* context) |
| 69 { | 69 { |
| 70 if (context->isDocument()) { | 70 if (context->isDocument()) { |
| 71 LocalFrame* frame = toDocument(context)->frame(); | 71 LocalFrame* frame = toDocument(context)->frame(); |
| 72 if (!frame) { | 72 if (!frame) { |
| 73 WTF_LOG(Timers, "ScheduledAction::execute %p: no frame", this); | 73 DVLOG(1) << "ScheduledAction::execute " << this << ": no frame"; |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) { | 76 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) { |
| 77 WTF_LOG(Timers, "ScheduledAction::execute %p: frame can not execute
scripts", this); | 77 DVLOG(1) << "ScheduledAction::execute " << this << ": frame can not
execute scripts"; |
| 78 return; | 78 return; |
| 79 } | 79 } |
| 80 execute(frame); | 80 execute(frame); |
| 81 } else { | 81 } else { |
| 82 WTF_LOG(Timers, "ScheduledAction::execute %p: worker scope", this); | 82 DVLOG(1) << "ScheduledAction::execute " << this << ": worker scope"; |
| 83 execute(toWorkerGlobalScope(context)); | 83 execute(toWorkerGlobalScope(context)); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 ScheduledAction::ScheduledAction(ScriptState* scriptState, const ScriptValue& fu
nction, const Vector<ScriptValue>& arguments) | 87 ScheduledAction::ScheduledAction(ScriptState* scriptState, const ScriptValue& fu
nction, const Vector<ScriptValue>& arguments) |
| 88 : m_scriptState(scriptState) | 88 : m_scriptState(scriptState) |
| 89 , m_info(scriptState->isolate()) | 89 , m_info(scriptState->isolate()) |
| 90 , m_code(String(), KURL(), TextPosition::belowRangePosition()) | 90 , m_code(String(), KURL(), TextPosition::belowRangePosition()) |
| 91 { | 91 { |
| 92 ASSERT(function.isFunction()); | 92 ASSERT(function.isFunction()); |
| 93 m_function.set(scriptState->isolate(), v8::Local<v8::Function>::Cast(functio
n.v8Value())); | 93 m_function.set(scriptState->isolate(), v8::Local<v8::Function>::Cast(functio
n.v8Value())); |
| 94 m_info.ReserveCapacity(arguments.size()); | 94 m_info.ReserveCapacity(arguments.size()); |
| 95 for (const ScriptValue& argument : arguments) | 95 for (const ScriptValue& argument : arguments) |
| 96 m_info.Append(argument.v8Value()); | 96 m_info.Append(argument.v8Value()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code) | 99 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code) |
| 100 : m_scriptState(scriptState) | 100 : m_scriptState(scriptState) |
| 101 , m_info(scriptState->isolate()) | 101 , m_info(scriptState->isolate()) |
| 102 , m_code(code, KURL()) | 102 , m_code(code, KURL()) |
| 103 { | 103 { |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ScheduledAction::execute(LocalFrame* frame) | 106 void ScheduledAction::execute(LocalFrame* frame) |
| 107 { | 107 { |
| 108 if (!m_scriptState->contextIsValid()) { | 108 if (!m_scriptState->contextIsValid()) { |
| 109 WTF_LOG(Timers, "ScheduledAction::execute %p: context is empty", this); | 109 DVLOG(1) << "ScheduledAction::execute " << this << ": context is empty"; |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 | 112 |
| 113 TRACE_EVENT0("v8", "ScheduledAction::execute"); | 113 TRACE_EVENT0("v8", "ScheduledAction::execute"); |
| 114 ScriptState::Scope scope(m_scriptState.get()); | 114 ScriptState::Scope scope(m_scriptState.get()); |
| 115 if (!m_function.isEmpty()) { | 115 if (!m_function.isEmpty()) { |
| 116 WTF_LOG(Timers, "ScheduledAction::execute %p: have function", this); | 116 DVLOG(1) << "ScheduledAction::execute " << this << ": have function"; |
| 117 Vector<v8::Local<v8::Value>> info; | 117 Vector<v8::Local<v8::Value>> info; |
| 118 createLocalHandlesForArgs(&info); | 118 createLocalHandlesForArgs(&info); |
| 119 frame->script().callFunction(m_function.newLocal(m_scriptState->isolate(
)), m_scriptState->context()->Global(), info.size(), info.data()); | 119 frame->script().callFunction(m_function.newLocal(m_scriptState->isolate(
)), m_scriptState->context()->Global(), info.size(), info.data()); |
| 120 } else { | 120 } else { |
| 121 WTF_LOG(Timers, "ScheduledAction::execute %p: executing from source", th
is); | 121 DVLOG(1) << "ScheduledAction::execute " << this << ": executing from sou
rce"; |
| 122 frame->script().executeScriptAndReturnValue(m_scriptState->context(), Sc
riptSourceCode(m_code)); | 122 frame->script().executeScriptAndReturnValue(m_scriptState->context(), Sc
riptSourceCode(m_code)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // The frame might be invalid at this point because JavaScript could have re
leased it. | 125 // The frame might be invalid at this point because JavaScript could have re
leased it. |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ScheduledAction::execute(WorkerGlobalScope* worker) | 128 void ScheduledAction::execute(WorkerGlobalScope* worker) |
| 129 { | 129 { |
| 130 ASSERT(worker->thread()->isCurrentThread()); | 130 ASSERT(worker->thread()->isCurrentThread()); |
| 131 ASSERT(m_scriptState->contextIsValid()); | 131 ASSERT(m_scriptState->contextIsValid()); |
| 132 if (!m_function.isEmpty()) { | 132 if (!m_function.isEmpty()) { |
| 133 ScriptState::Scope scope(m_scriptState.get()); | 133 ScriptState::Scope scope(m_scriptState.get()); |
| 134 Vector<v8::Local<v8::Value>> info; | 134 Vector<v8::Local<v8::Value>> info; |
| 135 createLocalHandlesForArgs(&info); | 135 createLocalHandlesForArgs(&info); |
| 136 V8ScriptRunner::callFunction(m_function.newLocal(m_scriptState->isolate(
)), worker, m_scriptState->context()->Global(), info.size(), info.data(), m_scri
ptState->isolate()); | 136 V8ScriptRunner::callFunction(m_function.newLocal(m_scriptState->isolate(
)), worker, m_scriptState->context()->Global(), info.size(), info.data(), m_scri
ptState->isolate()); |
| 137 } else { | 137 } else { |
| 138 worker->scriptController()->evaluate(m_code); | 138 worker->scriptController()->evaluate(m_code); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Local<v8::Value>>* ha
ndles) | 142 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Local<v8::Value>>* ha
ndles) |
| 143 { | 143 { |
| 144 handles->reserveCapacity(m_info.Size()); | 144 handles->reserveCapacity(m_info.Size()); |
| 145 for (size_t i = 0; i < m_info.Size(); ++i) | 145 for (size_t i = 0; i < m_info.Size(); ++i) |
| 146 handles->append(m_info.Get(i)); | 146 handles->append(m_info.Get(i)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |