Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 15 matching lines...) Expand all Loading... | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/V8NodeFilterCondition.h" | 32 #include "bindings/v8/V8NodeFilterCondition.h" |
| 33 | 33 |
| 34 #include "V8Node.h" | 34 #include "V8Node.h" |
| 35 #include "bindings/v8/ScriptController.h" | 35 #include "bindings/v8/ScriptController.h" |
| 36 #include "bindings/v8/ScriptState.h" | |
| 37 #include "bindings/v8/V8HiddenValue.h" | 36 #include "bindings/v8/V8HiddenValue.h" |
| 38 #include "core/dom/Node.h" | 37 #include "core/dom/Node.h" |
| 39 #include "core/dom/NodeFilter.h" | 38 #include "core/dom/NodeFilter.h" |
| 40 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 41 | 40 |
| 42 namespace WebCore { | 41 namespace WebCore { |
| 43 | 42 |
| 44 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::H andle<v8::Object> owner, v8::Isolate* isolate) | 43 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::H andle<v8::Object> owner, v8::Isolate* isolate) |
| 45 : m_filter(isolate, filter) | 44 : m_filter(isolate, filter) |
| 46 { | 45 { |
| 47 V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isola te), filter); | 46 V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isola te), filter); |
| 48 m_filter.setWeak(this, &setWeakCallback); | 47 m_filter.setWeak(this, &setWeakCallback); |
| 49 } | 48 } |
| 50 | 49 |
| 51 V8NodeFilterCondition::~V8NodeFilterCondition() | 50 V8NodeFilterCondition::~V8NodeFilterCondition() |
| 52 { | 51 { |
| 53 } | 52 } |
| 54 | 53 |
| 55 short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const | 54 short V8NodeFilterCondition::acceptNode(Node* node, ExceptionState& exceptionSta te) const |
| 56 { | 55 { |
| 57 v8::Isolate* isolate = state->isolate(); | 56 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
|
dcarney
2014/04/04 12:14:43
please cache isolate from constructor and use it h
haraken
2014/04/04 12:21:37
Done. I cached NewScriptState, which is exactly wh
| |
| 58 ASSERT(isolate->InContext()); | 57 ASSERT(isolate->InContext()); |
| 59 v8::HandleScope handleScope(isolate); | 58 v8::HandleScope handleScope(isolate); |
| 60 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); | 59 v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); |
| 61 ASSERT(!filter.IsEmpty()); | 60 ASSERT(!filter.IsEmpty()); |
| 62 // FIXME: Remove the filter.IsEmpty() check because |filter| must not be emp ty. | 61 // FIXME: Remove the filter.IsEmpty() check because |filter| must not be emp ty. |
| 63 // See crbug.com/358858 for more details. | 62 // See crbug.com/358858 for more details. |
| 64 if (filter.IsEmpty() || !filter->IsObject()) | 63 if (filter.IsEmpty() || !filter->IsObject()) |
| 65 return NodeFilter::FILTER_ACCEPT; | 64 return NodeFilter::FILTER_ACCEPT; |
| 66 | 65 |
| 67 v8::TryCatch exceptionCatcher; | 66 v8::TryCatch exceptionCatcher; |
| 68 | 67 |
| 69 v8::Handle<v8::Function> callback; | 68 v8::Handle<v8::Function> callback; |
| 70 if (filter->IsFunction()) | 69 if (filter->IsFunction()) |
| 71 callback = v8::Handle<v8::Function>::Cast(filter); | 70 callback = v8::Handle<v8::Function>::Cast(filter); |
| 72 else { | 71 else { |
| 73 v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isol ate, "acceptNode")); | 72 v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isol ate, "acceptNode")); |
| 74 if (value.IsEmpty() || !value->IsFunction()) { | 73 if (value.IsEmpty() || !value->IsFunction()) { |
| 75 throwTypeError("NodeFilter object does not have an acceptNode functi on", state->isolate()); | 74 throwTypeError("NodeFilter object does not have an acceptNode functi on", isolate); |
| 76 return NodeFilter::FILTER_REJECT; | 75 return NodeFilter::FILTER_REJECT; |
| 77 } | 76 } |
| 78 callback = v8::Handle<v8::Function>::Cast(value); | 77 callback = v8::Handle<v8::Function>::Cast(value); |
| 79 } | 78 } |
| 80 | 79 |
| 81 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu e>[1]); | 80 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu e>[1]); |
| 82 info[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate()); | 81 info[0] = toV8(node, v8::Handle<v8::Object>(), isolate); |
| 83 | 82 |
| 84 v8::Handle<v8::Object> object = isolate->GetCurrentContext()->Global(); | 83 v8::Handle<v8::Object> object = isolate->GetCurrentContext()->Global(); |
|
haraken
2014/04/04 12:21:37
So I changed this to m_scriptState->context().
| |
| 85 v8::Handle<v8::Value> result = ScriptController::callFunction(state->executi onContext(), callback, object, 1, info.get(), isolate); | 84 v8::Handle<v8::Value> result = ScriptController::callFunction(currentExecuti onContext(isolate), callback, object, 1, info.get(), isolate); |
|
haraken
2014/04/04 12:21:37
I changed this to m_scriptState->executionContext(
| |
| 86 | 85 |
| 87 if (exceptionCatcher.HasCaught()) { | 86 if (exceptionCatcher.HasCaught()) { |
| 88 state->setException(exceptionCatcher.Exception()); | 87 exceptionState.rethrowV8Exception(exceptionCatcher.Exception()); |
| 89 return NodeFilter::FILTER_REJECT; | 88 return NodeFilter::FILTER_REJECT; |
| 90 } | 89 } |
| 91 | 90 |
| 92 ASSERT(!result.IsEmpty()); | 91 ASSERT(!result.IsEmpty()); |
| 93 | 92 |
| 94 return result->Int32Value(); | 93 return result->Int32Value(); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackData<v8::Value , V8NodeFilterCondition>& data) | 96 void V8NodeFilterCondition::setWeakCallback(const v8::WeakCallbackData<v8::Value , V8NodeFilterCondition>& data) |
| 98 { | 97 { |
| 99 data.GetParameter()->m_filter.clear(); | 98 data.GetParameter()->m_filter.clear(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace WebCore | 101 } // namespace WebCore |
| OLD | NEW |