Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8NodeFilterCondition.cpp

Issue 1493023004: Add use counters for NodeFilter being a function or an object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/V8NodeFilterCondition.h" 32 #include "bindings/core/v8/V8NodeFilterCondition.h"
33 33
34 #include "bindings/core/v8/ScriptController.h" 34 #include "bindings/core/v8/ScriptController.h"
35 #include "bindings/core/v8/V8HiddenValue.h" 35 #include "bindings/core/v8/V8HiddenValue.h"
36 #include "bindings/core/v8/V8Node.h" 36 #include "bindings/core/v8/V8Node.h"
37 #include "core/dom/Node.h" 37 #include "core/dom/Node.h"
38 #include "core/dom/NodeFilter.h" 38 #include "core/dom/NodeFilter.h"
39 #include "core/frame/UseCounter.h"
39 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 V8NodeFilterCondition::V8NodeFilterCondition(v8::Local<v8::Value> filter, v8::Lo cal<v8::Object> owner, ScriptState* scriptState) 44 V8NodeFilterCondition::V8NodeFilterCondition(v8::Local<v8::Value> filter, v8::Lo cal<v8::Object> owner, ScriptState* scriptState)
44 : m_scriptState(scriptState) 45 : m_scriptState(scriptState)
45 { 46 {
46 // ..acceptNode(..) will only dispatch m_filter if m_filter->IsObject(). 47 // ..acceptNode(..) will only dispatch m_filter if m_filter->IsObject().
47 // We'll make sure m_filter is either usable by acceptNode or empty. 48 // We'll make sure m_filter is either usable by acceptNode or empty.
48 // (See the fast/dom/node-filter-gc test for a case where 'empty' happens.) 49 // (See the fast/dom/node-filter-gc test for a case where 'empty' happens.)
(...skipping 17 matching lines...) Expand all
66 67
67 ASSERT(filter.IsEmpty() || filter->IsObject()); 68 ASSERT(filter.IsEmpty() || filter->IsObject());
68 if (filter.IsEmpty()) 69 if (filter.IsEmpty())
69 return NodeFilter::FILTER_ACCEPT; 70 return NodeFilter::FILTER_ACCEPT;
70 71
71 v8::TryCatch exceptionCatcher(isolate); 72 v8::TryCatch exceptionCatcher(isolate);
72 73
73 v8::Local<v8::Function> callback; 74 v8::Local<v8::Function> callback;
74 v8::Local<v8::Value> receiver; 75 v8::Local<v8::Value> receiver;
75 if (filter->IsFunction()) { 76 if (filter->IsFunction()) {
77 UseCounter::countIfNotPrivateScript(isolate, callingExecutionContext(iso late), UseCounter::NodeFilterIsFunction);
76 callback = v8::Local<v8::Function>::Cast(filter); 78 callback = v8::Local<v8::Function>::Cast(filter);
77 receiver = v8::Undefined(isolate); 79 receiver = v8::Undefined(isolate);
78 } else { 80 } else {
79 v8::Local<v8::Object> filterObject; 81 v8::Local<v8::Object> filterObject;
80 if (!filter->ToObject(m_scriptState->context()).ToLocal(&filterObject)) { 82 if (!filter->ToObject(m_scriptState->context()).ToLocal(&filterObject)) {
81 exceptionState.throwTypeError("NodeFilter is not an object"); 83 exceptionState.throwTypeError("NodeFilter is not an object");
82 return NodeFilter::FILTER_REJECT; 84 return NodeFilter::FILTER_REJECT;
83 } 85 }
84 v8::Local<v8::Value> value; 86 v8::Local<v8::Value> value;
85 if (!filterObject->Get(m_scriptState->context(), v8AtomicString(isolate, "acceptNode")).ToLocal(&value) || !value->IsFunction()) { 87 if (!filterObject->Get(m_scriptState->context(), v8AtomicString(isolate, "acceptNode")).ToLocal(&value) || !value->IsFunction()) {
86 exceptionState.throwTypeError("NodeFilter object does not have an ac ceptNode function"); 88 exceptionState.throwTypeError("NodeFilter object does not have an ac ceptNode function");
87 return NodeFilter::FILTER_REJECT; 89 return NodeFilter::FILTER_REJECT;
88 } 90 }
91 UseCounter::countIfNotPrivateScript(isolate, callingExecutionContext(iso late), UseCounter::NodeFilterIsObject);
89 callback = v8::Local<v8::Function>::Cast(value); 92 callback = v8::Local<v8::Function>::Cast(value);
90 receiver = filter; 93 receiver = filter;
91 } 94 }
92 95
93 OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value> [1]); 96 OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value> [1]);
94 info[0] = toV8(node, m_scriptState->context()->Global(), isolate); 97 info[0] = toV8(node, m_scriptState->context()->Global(), isolate);
95 if (info[0].IsEmpty()) { 98 if (info[0].IsEmpty()) {
96 if (exceptionCatcher.HasCaught()) 99 if (exceptionCatcher.HasCaught())
97 exceptionState.rethrowV8Exception(exceptionCatcher.Exception()); 100 exceptionState.rethrowV8Exception(exceptionCatcher.Exception());
98 return NodeFilter::FILTER_REJECT; 101 return NodeFilter::FILTER_REJECT;
(...skipping 14 matching lines...) Expand all
113 } 116 }
114 return uint32Value; 117 return uint32Value;
115 } 118 }
116 119
117 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackInfo<V8NodeFil terCondition>& data) 120 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackInfo<V8NodeFil terCondition>& data)
118 { 121 {
119 data.GetParameter()->m_filter.clear(); 122 data.GetParameter()->m_filter.clear();
120 } 123 }
121 124
122 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698