OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 28 matching lines...) Expand all Loading... |
39 #include "core/dom/MutationObserver.h" | 39 #include "core/dom/MutationObserver.h" |
40 #include "core/dom/Node.h" | 40 #include "core/dom/Node.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 void V8MutationObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 44 void V8MutationObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
45 { | 45 { |
46 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Mutation
Observer", info.Holder(), info.GetIsolate()); | 46 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Mutation
Observer", info.Holder(), info.GetIsolate()); |
47 if (info.Length() < 1) { | 47 if (info.Length() < 1) { |
48 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); | 48 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); |
49 exceptionState.throwIfNeeded(); | |
50 return; | 49 return; |
51 } | 50 } |
52 | 51 |
53 v8::Local<v8::Value> arg = info[0]; | 52 v8::Local<v8::Value> arg = info[0]; |
54 if (!arg->IsFunction()) { | 53 if (!arg->IsFunction()) { |
55 exceptionState.throwTypeError("Callback argument must be a function"); | 54 exceptionState.throwTypeError("Callback argument must be a function"); |
56 exceptionState.throwIfNeeded(); | |
57 return; | 55 return; |
58 } | 56 } |
59 | 57 |
60 v8::Local<v8::Object> wrapper = info.Holder(); | 58 v8::Local<v8::Object> wrapper = info.Holder(); |
61 | 59 |
62 MutationCallback* callback = V8MutationCallback::create(v8::Local<v8::Functi
on>::Cast(arg), wrapper, ScriptState::current(info.GetIsolate())); | 60 MutationCallback* callback = V8MutationCallback::create(v8::Local<v8::Functi
on>::Cast(arg), wrapper, ScriptState::current(info.GetIsolate())); |
63 MutationObserver* observer = MutationObserver::create(callback); | 61 MutationObserver* observer = MutationObserver::create(callback); |
64 | 62 |
65 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); | 63 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); |
66 } | 64 } |
67 | 65 |
68 void V8MutationObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable*
scriptWrappable, const v8::Persistent<v8::Object>& wrapper) | 66 void V8MutationObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable*
scriptWrappable, const v8::Persistent<v8::Object>& wrapper) |
69 { | 67 { |
70 MutationObserver* observer = scriptWrappable->toImpl<MutationObserver>(); | 68 MutationObserver* observer = scriptWrappable->toImpl<MutationObserver>(); |
71 HeapHashSet<Member<Node>> observedNodes = observer->getObservedNodes(); | 69 HeapHashSet<Member<Node>> observedNodes = observer->getObservedNodes(); |
72 for (HeapHashSet<Member<Node>>::iterator it = observedNodes.begin(); it != o
bservedNodes.end(); ++it) { | 70 for (HeapHashSet<Member<Node>>::iterator it = observedNodes.begin(); it != o
bservedNodes.end(); ++it) { |
73 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor
GC(isolate, *it))); | 71 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor
GC(isolate, *it))); |
74 isolate->SetReferenceFromGroup(id, wrapper); | 72 isolate->SetReferenceFromGroup(id, wrapper); |
75 } | 73 } |
76 } | 74 } |
77 | 75 |
78 } // namespace blink | 76 } // namespace blink |
OLD | NEW |