| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (forgetV8EventObject(event)) | 90 if (forgetV8EventObject(event)) |
| 91 event->deref(); | 91 event->deref(); |
| 92 } | 92 } |
| 93 m_events.clear(); | 93 m_events.clear(); |
| 94 | 94 |
| 95 // Dispose the context. | 95 // Dispose the context. |
| 96 if (!m_context.IsEmpty()) { | 96 if (!m_context.IsEmpty()) { |
| 97 m_context.Dispose(); | 97 m_context.Dispose(); |
| 98 m_context.Clear(); | 98 m_context.Clear(); |
| 99 } | 99 } |
| 100 | |
| 101 // Remove the wrapping between JS object and DOM object. This is because | |
| 102 // the worker context object is going to be disposed immediately when a | |
| 103 // worker thread is tearing down. We do not want to re-delete the real objec
t | |
| 104 // when JS object is garbage collected. | |
| 105 v8::Locker locker; | |
| 106 v8::HandleScope scope; | |
| 107 v8::Persistent<v8::Object> wrapper = domObjectMap().get(m_workerContext); | |
| 108 if (!wrapper.IsEmpty()) | |
| 109 V8Proxy::SetDOMWrapper(wrapper, V8ClassIndex::INVALID_CLASS_INDEX, NULL)
; | |
| 110 domObjectMap().forget(m_workerContext); | |
| 111 } | 100 } |
| 112 | 101 |
| 113 WorkerContextExecutionProxy* WorkerContextExecutionProxy::retrieve() | 102 WorkerContextExecutionProxy* WorkerContextExecutionProxy::retrieve() |
| 114 { | 103 { |
| 115 v8::Handle<v8::Context> context = v8::Context::GetCurrent(); | 104 v8::Handle<v8::Context> context = v8::Context::GetCurrent(); |
| 116 v8::Handle<v8::Object> global = context->Global(); | 105 v8::Handle<v8::Object> global = context->Global(); |
| 117 global = V8Proxy::LookupDOMWrapper(V8ClassIndex::WORKERCONTEXT, global); | 106 global = V8Proxy::LookupDOMWrapper(V8ClassIndex::WORKERCONTEXT, global); |
| 118 ASSERT(!global.IsEmpty()); | 107 ASSERT(!global.IsEmpty()); |
| 119 WorkerContext* workerContext = V8Proxy::ToNativeObject<WorkerContext>(V8Clas
sIndex::WORKERCONTEXT, global); | 108 WorkerContext* workerContext = V8Proxy::ToNativeObject<WorkerContext>(V8Clas
sIndex::WORKERCONTEXT, global); |
| 120 return workerContext->script()->proxy(); | 109 return workerContext->script()->proxy(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 // Bail out if allocation failed. | 132 // Bail out if allocation failed. |
| 144 if (jsWorkerContext.IsEmpty()) { | 133 if (jsWorkerContext.IsEmpty()) { |
| 145 dispose(); | 134 dispose(); |
| 146 return; | 135 return; |
| 147 } | 136 } |
| 148 | 137 |
| 149 // Wrap the object. | 138 // Wrap the object. |
| 150 V8Proxy::SetDOMWrapper(jsWorkerContext, V8ClassIndex::ToInt(V8ClassIndex::WO
RKERCONTEXT), m_workerContext); | 139 V8Proxy::SetDOMWrapper(jsWorkerContext, V8ClassIndex::ToInt(V8ClassIndex::WO
RKERCONTEXT), m_workerContext); |
| 151 | 140 |
| 152 V8Proxy::SetJSWrapperForDOMObject(m_workerContext, v8::Persistent<v8::Object
>::New(jsWorkerContext)); | 141 V8Proxy::SetJSWrapperForDOMObject(m_workerContext, v8::Persistent<v8::Object
>::New(jsWorkerContext)); |
| 142 m_workerContext->ref(); |
| 153 | 143 |
| 154 // Insert the object instance as the prototype of the shadow object. | 144 // Insert the object instance as the prototype of the shadow object. |
| 155 v8::Handle<v8::Object> globalObject = m_context->Global(); | 145 v8::Handle<v8::Object> globalObject = m_context->Global(); |
| 156 globalObject->Set(implicitProtoString, jsWorkerContext); | 146 globalObject->Set(implicitProtoString, jsWorkerContext); |
| 157 } | 147 } |
| 158 | 148 |
| 159 v8::Local<v8::Function> WorkerContextExecutionProxy::GetConstructor(V8ClassIndex
::V8WrapperType type) | 149 v8::Local<v8::Function> WorkerContextExecutionProxy::GetConstructor(V8ClassIndex
::V8WrapperType type) |
| 160 { | 150 { |
| 161 // Enter the context of the proxy to make sure that the function is | 151 // Enter the context of the proxy to make sure that the function is |
| 162 // constructed in the context corresponding to this proxy. | 152 // constructed in the context corresponding to this proxy. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 348 } |
| 359 | 349 |
| 360 void WorkerContextExecutionProxy::trackEvent(Event* event) | 350 void WorkerContextExecutionProxy::trackEvent(Event* event) |
| 361 { | 351 { |
| 362 m_events.append(event); | 352 m_events.append(event); |
| 363 } | 353 } |
| 364 | 354 |
| 365 } // namespace WebCore | 355 } // namespace WebCore |
| 366 | 356 |
| 367 #endif // ENABLE(WORKERS) | 357 #endif // ENABLE(WORKERS) |
| OLD | NEW |