OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 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 30 matching lines...) Expand all Loading... |
41 #include "core/inspector/ScriptCallStack.h" | 41 #include "core/inspector/ScriptCallStack.h" |
42 #include "core/page/ContentSecurityPolicy.h" | 42 #include "core/page/ContentSecurityPolicy.h" |
43 #include "core/page/DOMTimer.h" | 43 #include "core/page/DOMTimer.h" |
44 #include "core/page/DOMWindowTimers.h" | 44 #include "core/page/DOMWindowTimers.h" |
45 #include "core/workers/WorkerGlobalScope.h" | 45 #include "core/workers/WorkerGlobalScope.h" |
46 #include "modules/websockets/WebSocket.h" | 46 #include "modules/websockets/WebSocket.h" |
47 #include "wtf/OwnArrayPtr.h" | 47 #include "wtf/OwnArrayPtr.h" |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) | 51 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, DOMTi
mer::Type timerType) |
52 { | 52 { |
53 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); | 53 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); |
54 | 54 |
55 int argumentCount = args.Length(); | 55 int argumentCount = args.Length(); |
56 if (argumentCount < 1) | 56 if (argumentCount < 1) |
57 return; | 57 return; |
58 | 58 |
59 v8::Handle<v8::Value> function = args[0]; | 59 v8::Handle<v8::Value> function = args[0]; |
60 | 60 |
61 WorkerScriptController* script = workerGlobalScope->script(); | 61 WorkerScriptController* script = workerGlobalScope->script(); |
(...skipping 18 matching lines...) Expand all Loading... |
80 for (size_t i = 0; i < paramCount; ++i) | 80 for (size_t i = 0; i < paramCount; ++i) |
81 params[i] = args[i+2]; | 81 params[i] = args[i+2]; |
82 } | 82 } |
83 // ScheduledAction takes ownership of actual params and releases them in
its destructor. | 83 // ScheduledAction takes ownership of actual params and releases them in
its destructor. |
84 action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function
>::Cast(function), paramCount, params.get(), args.GetIsolate())); | 84 action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function
>::Cast(function), paramCount, params.get(), args.GetIsolate())); |
85 } else | 85 } else |
86 return; | 86 return; |
87 | 87 |
88 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; | 88 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; |
89 int timerId; | 89 int timerId; |
90 if (singleShot) | 90 switch (timerType) { |
| 91 case DOMTimer::TimeoutType: |
91 timerId = DOMWindowTimers::setTimeout(workerGlobalScope, action.release(
), timeout); | 92 timerId = DOMWindowTimers::setTimeout(workerGlobalScope, action.release(
), timeout); |
92 else | 93 break; |
| 94 case DOMTimer::IntervalType: |
93 timerId = DOMWindowTimers::setInterval(workerGlobalScope, action.release
(), timeout); | 95 timerId = DOMWindowTimers::setInterval(workerGlobalScope, action.release
(), timeout); |
| 96 break; |
| 97 } |
94 | 98 |
95 v8SetReturnValue(args, timerId); | 99 v8SetReturnValue(args, timerId); |
96 } | 100 } |
97 | 101 |
98 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) | 102 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) |
99 { | 103 { |
100 if (!args.Length()) | 104 if (!args.Length()) |
101 return; | 105 return; |
102 | 106 |
103 Vector<String> urls; | 107 Vector<String> urls; |
104 for (int i = 0; i < args.Length(); i++) { | 108 for (int i = 0; i < args.Length(); i++) { |
105 V8TRYCATCH_VOID(v8::Handle<v8::String>, scriptUrl, args[i]->ToString()); | 109 V8TRYCATCH_VOID(v8::Handle<v8::String>, scriptUrl, args[i]->ToString()); |
106 if (scriptUrl.IsEmpty()) | 110 if (scriptUrl.IsEmpty()) |
107 return; | 111 return; |
108 urls.append(toWebCoreString(scriptUrl)); | 112 urls.append(toWebCoreString(scriptUrl)); |
109 } | 113 } |
110 | 114 |
111 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); | 115 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); |
112 | 116 |
113 ExceptionCode ec = 0; | 117 ExceptionCode ec = 0; |
114 workerGlobalScope->importScripts(urls, ec); | 118 workerGlobalScope->importScripts(urls, ec); |
115 | 119 |
116 if (!ec) | 120 if (!ec) |
117 return; | 121 return; |
118 setDOMException(ec, args.GetIsolate()); | 122 setDOMException(ec, args.GetIsolate()); |
119 } | 123 } |
120 | 124 |
121 void V8WorkerGlobalScope::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& args) | 125 void V8WorkerGlobalScope::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& args) |
122 { | 126 { |
123 return SetTimeoutOrInterval(args, true); | 127 return SetTimeoutOrInterval(args, DOMTimer::TimeoutType); |
124 } | 128 } |
125 | 129 |
126 void V8WorkerGlobalScope::setIntervalMethodCustom(const v8::FunctionCallbackInfo
<v8::Value>& args) | 130 void V8WorkerGlobalScope::setIntervalMethodCustom(const v8::FunctionCallbackInfo
<v8::Value>& args) |
127 { | 131 { |
128 return SetTimeoutOrInterval(args, false); | 132 return SetTimeoutOrInterval(args, DOMTimer::IntervalType); |
129 } | 133 } |
130 | 134 |
131 v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creat
ionContext, v8::Isolate* isolate) | 135 v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creat
ionContext, v8::Isolate* isolate) |
132 { | 136 { |
133 // Notice that we explicitly ignore creationContext because the WorkerGlobal
Scope is its own creationContext. | 137 // Notice that we explicitly ignore creationContext because the WorkerGlobal
Scope is its own creationContext. |
134 | 138 |
135 if (!impl) | 139 if (!impl) |
136 return v8NullWithCheck(isolate); | 140 return v8NullWithCheck(isolate); |
137 | 141 |
138 WorkerScriptController* script = impl->script(); | 142 WorkerScriptController* script = impl->script(); |
139 if (!script) | 143 if (!script) |
140 return v8NullWithCheck(isolate); | 144 return v8NullWithCheck(isolate); |
141 | 145 |
142 v8::Handle<v8::Object> global = script->context()->Global(); | 146 v8::Handle<v8::Object> global = script->context()->Global(); |
143 ASSERT(!global.IsEmpty()); | 147 ASSERT(!global.IsEmpty()); |
144 return global; | 148 return global; |
145 } | 149 } |
146 | 150 |
147 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) | 151 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) |
148 { | 152 { |
149 return toV8(impl, creationContext, isolate); | 153 return toV8(impl, creationContext, isolate); |
150 } | 154 } |
151 | 155 |
152 } // namespace WebCore | 156 } // namespace WebCore |
OLD | NEW |