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 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 case Node::DOCUMENT_FRAGMENT_NODE: | 2383 case Node::DOCUMENT_FRAGMENT_NODE: |
2384 type = V8ClassIndex::DOCUMENTFRAGMENT; | 2384 type = V8ClassIndex::DOCUMENTFRAGMENT; |
2385 break; | 2385 break; |
2386 case Node::ENTITY_REFERENCE_NODE: | 2386 case Node::ENTITY_REFERENCE_NODE: |
2387 type = V8ClassIndex::ENTITYREFERENCE; | 2387 type = V8ClassIndex::ENTITYREFERENCE; |
2388 break; | 2388 break; |
2389 default: | 2389 default: |
2390 type = V8ClassIndex::NODE; | 2390 type = V8ClassIndex::NODE; |
2391 } | 2391 } |
2392 | 2392 |
| 2393 // Find the context to which the node belongs and create the wrapper |
| 2394 // in that context. If the node is not in a document, the current |
| 2395 // context is used. |
| 2396 v8::Local<v8::Context> context; |
| 2397 Document* doc = node->document(); |
| 2398 if (doc) { |
| 2399 context = V8Proxy::GetContext(doc->frame()); |
| 2400 } |
| 2401 if (!context.IsEmpty()) { |
| 2402 context->Enter(); |
| 2403 } |
| 2404 |
2393 // Set the peer object for future access. | 2405 // Set the peer object for future access. |
2394 // InstantiateV8Object automatically casts node to Peerable*. | 2406 // InstantiateV8Object automatically casts node to Peerable*. |
2395 v8::Local<v8::Object> result = | 2407 v8::Local<v8::Object> result = |
2396 InstantiateV8Object(type, V8ClassIndex::NODE, node); | 2408 InstantiateV8Object(type, V8ClassIndex::NODE, node); |
| 2409 |
| 2410 // Exit the node's context if it was entered. |
| 2411 if (!context.IsEmpty()) { |
| 2412 context->Exit(); |
| 2413 } |
| 2414 |
2397 if (result.IsEmpty()) { | 2415 if (result.IsEmpty()) { |
2398 // If instantiation failed it's important not to add the result | 2416 // If instantiation failed it's important not to add the result |
2399 // to the DOM node map. Instead we return an empty handle, which | 2417 // to the DOM node map. Instead we return an empty handle, which |
2400 // should already be handled by callers of this function in case | 2418 // should already be handled by callers of this function in case |
2401 // the node is NULL. | 2419 // the node is NULL. |
2402 return result; | 2420 return result; |
2403 } | 2421 } |
2404 | 2422 |
2405 dom_node_map().set(node, v8::Persistent<v8::Object>::New(result)); | 2423 dom_node_map().set(node, v8::Persistent<v8::Object>::New(result)); |
2406 | 2424 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2639 v8::Handle<v8::Object> global = context->Global(); | 2657 v8::Handle<v8::Object> global = context->Global(); |
2640 global->Set(v8::String::New(name), instance); | 2658 global->Set(v8::String::New(name), instance); |
2641 } | 2659 } |
2642 | 2660 |
2643 void V8Proxy::ProcessConsoleMessages() | 2661 void V8Proxy::ProcessConsoleMessages() |
2644 { | 2662 { |
2645 ConsoleMessageManager::ProcessDelayedMessages(); | 2663 ConsoleMessageManager::ProcessDelayedMessages(); |
2646 } | 2664 } |
2647 | 2665 |
2648 } // namespace WebCore | 2666 } // namespace WebCore |
OLD | NEW |