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

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

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 months 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) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 worker_global_scope_(nullptr) { 56 worker_global_scope_(nullptr) {
57 if (IsMainThread()) 57 if (IsMainThread())
58 InstanceCounters::IncrementCounter( 58 InstanceCounters::IncrementCounter(
59 InstanceCounters::kJSEventListenerCounter); 59 InstanceCounters::kJSEventListenerCounter);
60 else 60 else
61 worker_global_scope_ = 61 worker_global_scope_ =
62 ToWorkerGlobalScope(CurrentExecutionContext(isolate)); 62 ToWorkerGlobalScope(CurrentExecutionContext(isolate));
63 } 63 }
64 64
65 V8AbstractEventListener::~V8AbstractEventListener() { 65 V8AbstractEventListener::~V8AbstractEventListener() {
66 ASSERT(listener_.IsEmpty()); 66 DCHECK(listener_.IsEmpty());
67 if (IsMainThread()) 67 if (IsMainThread())
68 InstanceCounters::DecrementCounter( 68 InstanceCounters::DecrementCounter(
69 InstanceCounters::kJSEventListenerCounter); 69 InstanceCounters::kJSEventListenerCounter);
70 } 70 }
71 71
72 void V8AbstractEventListener::handleEvent(ExecutionContext* execution_context, 72 void V8AbstractEventListener::handleEvent(ExecutionContext* execution_context,
73 Event* event) { 73 Event* event) {
74 if (!execution_context) 74 if (!execution_context)
75 return; 75 return;
76 // Don't reenter V8 if execution was terminated in this instance of V8. 76 // Don't reenter V8 if execution was terminated in this instance of V8.
77 if (execution_context->IsJSExecutionForbidden()) 77 if (execution_context->IsJSExecutionForbidden())
78 return; 78 return;
79 79
80 // A ScriptState used by the event listener needs to be calculated based on 80 // A ScriptState used by the event listener needs to be calculated based on
81 // the ExecutionContext that fired the the event listener and the world 81 // the ExecutionContext that fired the the event listener and the world
82 // that installed the event listener. 82 // that installed the event listener.
83 ASSERT(event); 83 DCHECK(event);
84 v8::HandleScope handle_scope(ToIsolate(execution_context)); 84 v8::HandleScope handle_scope(ToIsolate(execution_context));
85 v8::Local<v8::Context> v8_context = ToV8Context(execution_context, World()); 85 v8::Local<v8::Context> v8_context = ToV8Context(execution_context, World());
86 if (v8_context.IsEmpty()) 86 if (v8_context.IsEmpty())
87 return; 87 return;
88 ScriptState* script_state = ScriptState::From(v8_context); 88 ScriptState* script_state = ScriptState::From(v8_context);
89 if (!script_state->ContextIsValid()) 89 if (!script_state->ContextIsValid())
90 return; 90 return;
91 HandleEvent(script_state, event); 91 HandleEvent(script_state, event);
92 } 92 }
93 93
94 void V8AbstractEventListener::HandleEvent(ScriptState* script_state, 94 void V8AbstractEventListener::HandleEvent(ScriptState* script_state,
95 Event* event) { 95 Event* event) {
96 ScriptState::Scope scope(script_state); 96 ScriptState::Scope scope(script_state);
97 97
98 // Get the V8 wrapper for the event object. 98 // Get the V8 wrapper for the event object.
99 v8::Local<v8::Value> js_event = 99 v8::Local<v8::Value> js_event =
100 ToV8(event, script_state->GetContext()->Global(), GetIsolate()); 100 ToV8(event, script_state->GetContext()->Global(), GetIsolate());
101 if (js_event.IsEmpty()) 101 if (js_event.IsEmpty())
102 return; 102 return;
103 InvokeEventHandler(script_state, event, 103 InvokeEventHandler(script_state, event,
104 v8::Local<v8::Value>::New(GetIsolate(), js_event)); 104 v8::Local<v8::Value>::New(GetIsolate(), js_event));
105 } 105 }
106 106
107 void V8AbstractEventListener::SetListenerObject( 107 void V8AbstractEventListener::SetListenerObject(
108 v8::Local<v8::Object> listener) { 108 v8::Local<v8::Object> listener) {
109 ASSERT(listener_.IsEmpty()); 109 DCHECK(listener_.IsEmpty());
110 // Balanced in wrapperCleared xor clearListenerObject. 110 // Balanced in wrapperCleared xor clearListenerObject.
111 if (worker_global_scope_) { 111 if (worker_global_scope_) {
112 worker_global_scope_->RegisterEventListener(this); 112 worker_global_scope_->RegisterEventListener(this);
113 } else { 113 } else {
114 keep_alive_ = this; 114 keep_alive_ = this;
115 } 115 }
116 listener_.Set(GetIsolate(), listener, this, &WrapperCleared); 116 listener_.Set(GetIsolate(), listener, this, &WrapperCleared);
117 } 117 }
118 118
119 void V8AbstractEventListener::InvokeEventHandler( 119 void V8AbstractEventListener::InvokeEventHandler(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 DEFINE_TRACE(V8AbstractEventListener) { 231 DEFINE_TRACE(V8AbstractEventListener) {
232 visitor->Trace(worker_global_scope_); 232 visitor->Trace(worker_global_scope_);
233 EventListener::Trace(visitor); 233 EventListener::Trace(visitor);
234 } 234 }
235 235
236 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) { 236 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) {
237 visitor->TraceWrappers(listener_.Cast<v8::Value>()); 237 visitor->TraceWrappers(listener_.Cast<v8::Value>());
238 } 238 }
239 239
240 } // namespace blink 240 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698