OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // 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 2357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 // the outer window, and the outer window identify is preserved for | 2368 // the outer window, and the outer window identify is preserved for |
2369 // the frame. However, a new inner window is created for the new page. | 2369 // the frame. However, a new inner window is created for the new page. |
2370 // If there are JS code holds a closure to the old inner window, | 2370 // If there are JS code holds a closure to the old inner window, |
2371 // it won't be able to reach the outer window via its global object. | 2371 // it won't be able to reach the outer window via its global object. |
2372 void V8Proxy::InitContextIfNeeded() | 2372 void V8Proxy::InitContextIfNeeded() |
2373 { | 2373 { |
2374 // Bail out if the context has already been initialized. | 2374 // Bail out if the context has already been initialized. |
2375 if (!m_context.IsEmpty()) | 2375 if (!m_context.IsEmpty()) |
2376 return; | 2376 return; |
2377 | 2377 |
| 2378 // Create a handle scope for all local handles. |
| 2379 v8::HandleScope handle_scope; |
| 2380 |
2378 // Setup the security handlers and message listener. This only has | 2381 // Setup the security handlers and message listener. This only has |
2379 // to be done once. | 2382 // to be done once. |
2380 static bool v8_initialized = false; | 2383 static bool v8_initialized = false; |
2381 if (!v8_initialized) { | 2384 if (!v8_initialized) { |
2382 // Tells V8 not to call the default OOM handler, binding code | 2385 // Tells V8 not to call the default OOM handler, binding code |
2383 // will handle it. | 2386 // will handle it. |
2384 v8::V8::IgnoreOutOfMemoryException(); | 2387 v8::V8::IgnoreOutOfMemoryException(); |
2385 v8::V8::SetFatalErrorHandler(ReportFatalErrorInV8); | 2388 v8::V8::SetFatalErrorHandler(ReportFatalErrorInV8); |
2386 | 2389 |
2387 v8::V8::SetGlobalGCPrologueCallback(&GCPrologue); | 2390 v8::V8::SetGlobalGCPrologueCallback(&GCPrologue); |
2388 v8::V8::SetGlobalGCEpilogueCallback(&GCEpilogue); | 2391 v8::V8::SetGlobalGCEpilogueCallback(&GCEpilogue); |
2389 | 2392 |
2390 v8::V8::AddMessageListener(HandleConsoleMessage); | 2393 v8::V8::AddMessageListener(HandleConsoleMessage); |
2391 | 2394 |
2392 v8::V8::SetFailedAccessCheckCallbackFunction(ReportUnsafeJavaScriptAccess); | 2395 v8::V8::SetFailedAccessCheckCallbackFunction(ReportUnsafeJavaScriptAccess); |
2393 | 2396 |
2394 v8_initialized = true; | 2397 v8_initialized = true; |
2395 } | 2398 } |
2396 | 2399 |
2397 m_context = createNewContext(m_global); | 2400 m_context = createNewContext(m_global); |
2398 if (m_context.IsEmpty()) | 2401 if (m_context.IsEmpty()) |
2399 return; | 2402 return; |
2400 | 2403 |
2401 // Starting from now, use local context only. | 2404 // Starting from now, use local context only. |
2402 v8::Local<v8::Context> context = GetContext(); | 2405 v8::Local<v8::Context> context = GetContext(); |
2403 v8::Context::Scope scope(context); | 2406 v8::Context::Scope context_scope(context); |
2404 | 2407 |
2405 // Store the first global object created so we can reuse it. | 2408 // Store the first global object created so we can reuse it. |
2406 if (m_global.IsEmpty()) { | 2409 if (m_global.IsEmpty()) { |
2407 m_global = v8::Persistent<v8::Object>::New(context->Global()); | 2410 m_global = v8::Persistent<v8::Object>::New(context->Global()); |
2408 // Bail out if allocation of the first global objects fails. | 2411 // Bail out if allocation of the first global objects fails. |
2409 if (m_global.IsEmpty()) { | 2412 if (m_global.IsEmpty()) { |
2410 DisposeContextHandles(); | 2413 DisposeContextHandles(); |
2411 return; | 2414 return; |
2412 } | 2415 } |
2413 #ifndef NDEBUG | 2416 #ifndef NDEBUG |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3579 } | 3582 } |
3580 return ToWebCoreString(v8::Debug::Call(frame_source_name)); | 3583 return ToWebCoreString(v8::Debug::Call(frame_source_name)); |
3581 } | 3584 } |
3582 | 3585 |
3583 void V8Proxy::RegisterExtension(v8::Extension* extension) { | 3586 void V8Proxy::RegisterExtension(v8::Extension* extension) { |
3584 v8::RegisterExtension(extension); | 3587 v8::RegisterExtension(extension); |
3585 m_extensions.push_back(extension); | 3588 m_extensions.push_back(extension); |
3586 } | 3589 } |
3587 | 3590 |
3588 } // namespace WebCore | 3591 } // namespace WebCore |
OLD | NEW |