| 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 24 matching lines...) Expand all Loading... |
| 35 #include "V8MessagePort.h" | 35 #include "V8MessagePort.h" |
| 36 #include "V8MutationObserver.h" | 36 #include "V8MutationObserver.h" |
| 37 #include "V8Node.h" | 37 #include "V8Node.h" |
| 38 #include "V8ScriptRunner.h" | 38 #include "V8ScriptRunner.h" |
| 39 #include "bindings/v8/RetainedDOMInfo.h" | 39 #include "bindings/v8/RetainedDOMInfo.h" |
| 40 #include "bindings/v8/V8AbstractEventListener.h" | 40 #include "bindings/v8/V8AbstractEventListener.h" |
| 41 #include "bindings/v8/V8Binding.h" | 41 #include "bindings/v8/V8Binding.h" |
| 42 #include "bindings/v8/WrapperTypeInfo.h" | 42 #include "bindings/v8/WrapperTypeInfo.h" |
| 43 #include "core/dom/Attr.h" | 43 #include "core/dom/Attr.h" |
| 44 #include "core/dom/NodeTraversal.h" | 44 #include "core/dom/NodeTraversal.h" |
| 45 #include "core/dom/TemplateContentDocumentFragment.h" |
| 45 #include "core/dom/shadow/ElementShadow.h" | 46 #include "core/dom/shadow/ElementShadow.h" |
| 46 #include "core/dom/shadow/ShadowRoot.h" | 47 #include "core/dom/shadow/ShadowRoot.h" |
| 47 #include "core/html/HTMLImageElement.h" | 48 #include "core/html/HTMLImageElement.h" |
| 49 #include "core/html/HTMLTemplateElement.h" |
| 48 #include "platform/TraceEvent.h" | 50 #include "platform/TraceEvent.h" |
| 49 | 51 |
| 50 namespace WebCore { | 52 namespace WebCore { |
| 51 | 53 |
| 52 // FIXME: This should use opaque GC roots. | 54 // FIXME: This should use opaque GC roots. |
| 53 static void addReferencesForNodeWithEventListeners(v8::Isolate* isolate, Node* n
ode, const v8::Persistent<v8::Object>& wrapper) | 55 static void addReferencesForNodeWithEventListeners(v8::Isolate* isolate, Node* n
ode, const v8::Persistent<v8::Object>& wrapper) |
| 54 { | 56 { |
| 55 ASSERT(node->hasEventListeners()); | 57 ASSERT(node->hasEventListeners()); |
| 56 | 58 |
| 57 EventListenerIterator iterator(node); | 59 EventListenerIterator iterator(node); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 if (node->inDocument() || (node->hasTagName(HTMLNames::imgTag) && toHTMLImag
eElement(node)->hasPendingActivity())) | 79 if (node->inDocument() || (node->hasTagName(HTMLNames::imgTag) && toHTMLImag
eElement(node)->hasPendingActivity())) |
| 78 return &node->document(); | 80 return &node->document(); |
| 79 | 81 |
| 80 if (node->isAttributeNode()) { | 82 if (node->isAttributeNode()) { |
| 81 Node* ownerElement = toAttr(node)->ownerElement(); | 83 Node* ownerElement = toAttr(node)->ownerElement(); |
| 82 if (!ownerElement) | 84 if (!ownerElement) |
| 83 return node; | 85 return node; |
| 84 node = ownerElement; | 86 node = ownerElement; |
| 85 } | 87 } |
| 86 | 88 |
| 87 while (Node* parent = node->parentOrShadowHostNode()) | 89 while (Node* parent = node->parentOrShadowHostOrTemplateHostNode()) |
| 88 node = parent; | 90 node = parent; |
| 89 | 91 |
| 90 return node; | 92 return node; |
| 91 } | 93 } |
| 92 | 94 |
| 93 // Regarding a minor GC algorithm for DOM nodes, see this document: | 95 // Regarding a minor GC algorithm for DOM nodes, see this document: |
| 94 // https://docs.google.com/a/google.com/presentation/d/1uifwVYGNYTZDoGLyCb7sXa7g
49mWNMW2gaWvMN5NLk8/edit#slide=id.p | 96 // https://docs.google.com/a/google.com/presentation/d/1uifwVYGNYTZDoGLyCb7sXa7g
49mWNMW2gaWvMN5NLk8/edit#slide=id.p |
| 95 class MinorGCWrapperVisitor : public v8::PersistentHandleVisitor { | 97 class MinorGCWrapperVisitor : public v8::PersistentHandleVisitor { |
| 96 public: | 98 public: |
| 97 explicit MinorGCWrapperVisitor(v8::Isolate* isolate) | 99 explicit MinorGCWrapperVisitor(v8::Isolate* isolate) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 174 } |
| 173 if (ShadowRoot* shadowRoot = node->youngestShadowRoot()) { | 175 if (ShadowRoot* shadowRoot = node->youngestShadowRoot()) { |
| 174 if (!traverseTree(shadowRoot, newSpaceNodes)) | 176 if (!traverseTree(shadowRoot, newSpaceNodes)) |
| 175 return false; | 177 return false; |
| 176 } else if (node->isShadowRoot()) { | 178 } else if (node->isShadowRoot()) { |
| 177 if (ShadowRoot* shadowRoot = toShadowRoot(node)->olderShadowRoot
()) { | 179 if (ShadowRoot* shadowRoot = toShadowRoot(node)->olderShadowRoot
()) { |
| 178 if (!traverseTree(shadowRoot, newSpaceNodes)) | 180 if (!traverseTree(shadowRoot, newSpaceNodes)) |
| 179 return false; | 181 return false; |
| 180 } | 182 } |
| 181 } | 183 } |
| 184 // <template> has a |content| property holding a DOM fragment which
we must traverse, |
| 185 // just like we do for the shadow trees above. |
| 186 if (node->hasTagName(HTMLNames::templateTag)) { |
| 187 if (!traverseTree(toHTMLTemplateElement(node)->content(), newSpa
ceNodes)) |
| 188 return false; |
| 189 } |
| 182 } | 190 } |
| 183 return true; | 191 return true; |
| 184 } | 192 } |
| 185 | 193 |
| 186 void gcTree(v8::Isolate* isolate, Node* startNode) | 194 void gcTree(v8::Isolate* isolate, Node* startNode) |
| 187 { | 195 { |
| 188 Vector<Node*, initialNodeVectorSize> newSpaceNodes; | 196 Vector<Node*, initialNodeVectorSize> newSpaceNodes; |
| 189 | 197 |
| 190 Node* node = startNode; | 198 Node* node = startNode; |
| 191 while (node->parentOrShadowHostNode()) | 199 while (Node* parent = node->parentOrShadowHostOrTemplateHostNode()) |
| 192 node = node->parentOrShadowHostNode(); | 200 node = parent; |
| 193 | 201 |
| 194 if (!traverseTree(node, &newSpaceNodes)) | 202 if (!traverseTree(node, &newSpaceNodes)) |
| 195 return; | 203 return; |
| 196 | 204 |
| 197 // We completed the DOM tree traversal. All wrappers in the DOM tree are | 205 // We completed the DOM tree traversal. All wrappers in the DOM tree are |
| 198 // stored in newSpaceNodes and are expected to exist in the new space of
V8. | 206 // stored in newSpaceNodes and are expected to exist in the new space of
V8. |
| 199 // We report those wrappers to V8 as an object group. | 207 // We report those wrappers to V8 as an object group. |
| 200 Node** nodeIterator = newSpaceNodes.begin(); | 208 Node** nodeIterator = newSpaceNodes.begin(); |
| 201 Node** const nodeIteratorEnd = newSpaceNodes.end(); | 209 Node** const nodeIteratorEnd = newSpaceNodes.end(); |
| 202 if (nodeIterator == nodeIteratorEnd) | 210 if (nodeIterator == nodeIteratorEnd) |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 { | 422 { |
| 415 v8::HandleScope handleScope(isolate); | 423 v8::HandleScope handleScope(isolate); |
| 416 v8::Local<v8::Context> context = v8::Context::New(isolate); | 424 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 417 if (context.IsEmpty()) | 425 if (context.IsEmpty()) |
| 418 return; | 426 return; |
| 419 v8::Context::Scope contextScope(context); | 427 v8::Context::Scope contextScope(context); |
| 420 V8ScriptRunner::compileAndRunInternalScript(v8String("if (gc) gc();", isolat
e), isolate); | 428 V8ScriptRunner::compileAndRunInternalScript(v8String("if (gc) gc();", isolat
e), isolate); |
| 421 } | 429 } |
| 422 | 430 |
| 423 } // namespace WebCore | 431 } // namespace WebCore |
| OLD | NEW |