OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 CustomElementBinding* V8PerContextData::customElementBinding(CustomElementDefini
tion* definition) | 147 CustomElementBinding* V8PerContextData::customElementBinding(CustomElementDefini
tion* definition) |
148 { | 148 { |
149 CustomElementBindingMap::const_iterator it = m_customElementBindings->find(d
efinition); | 149 CustomElementBindingMap::const_iterator it = m_customElementBindings->find(d
efinition); |
150 ASSERT(it != m_customElementBindings->end()); | 150 ASSERT(it != m_customElementBindings->end()); |
151 return it->value.get(); | 151 return it->value.get(); |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId)
| 155 static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId) |
156 { | 156 { |
157 char buffer[32]; | 157 char buffer[32]; |
158 unsigned wanted; | 158 unsigned wanted; |
159 if (debugId == -1) | 159 if (debugId == -1) |
160 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); | 160 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); |
161 else | 161 else |
162 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); | 162 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); |
163 | 163 |
164 if (wanted < sizeof(buffer)) | 164 if (wanted < sizeof(buffer)) |
165 return v8::String::NewSymbol(buffer); | 165 return v8::String::NewSymbol(buffer); |
166 | 166 |
167 return v8::Undefined(); | 167 return v8::Undefined(); |
168 }; | 168 }; |
169 | 169 |
170 static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context) | 170 static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context) |
171 { | 171 { |
172 v8::Context::Scope contextScope(context); | 172 v8::Context::Scope contextScope(context); |
173 return context->GetEmbedderData(v8ContextDebugIdIndex); | 173 return context->GetEmbedderData(v8ContextDebugIdIndex); |
174 } | 174 } |
175 | 175 |
176 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value>
value) | 176 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value>
value) |
177 { | 177 { |
178 v8::Context::Scope contextScope(context); | 178 v8::Context::Scope contextScope(context); |
179 context->SetEmbedderData(v8ContextDebugIdIndex, value); | 179 context->SetEmbedderData(v8ContextDebugIdIndex, value); |
180 } | 180 } |
181 | 181 |
182 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context,
const char* worldName, int debugId) | 182 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context,
const char* worldName, int debugId) |
183 { | 183 { |
184 if (!debugData(context)->IsUndefined()) | 184 if (!debugData(context)->IsUndefined()) |
185 return false; | 185 return false; |
186 v8::HandleScope scope; | 186 v8::HandleScope scope; |
187 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); | 187 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); |
188 setDebugData(context, debugData); | 188 setDebugData(context, debugData); |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) | 192 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) |
193 { | 193 { |
194 v8::HandleScope scope; | 194 v8::HandleScope scope; |
195 v8::Handle<v8::Value> data = debugData(context); | 195 v8::Handle<v8::Value> data = debugData(context); |
196 | 196 |
197 if (!data->IsString()) | 197 if (!data->IsString()) |
198 return -1; | 198 return -1; |
199 v8::String::AsciiValue ascii(data); | 199 v8::String::AsciiValue ascii(data); |
200 char* comma = strnstr(*ascii, ",", ascii.length()); | 200 char* comma = strnstr(*ascii, ",", ascii.length()); |
201 if (!comma) | 201 if (!comma) |
202 return -1; | 202 return -1; |
203 return atoi(comma + 1); | 203 return atoi(comma + 1); |
204 } | 204 } |
205 | 205 |
206 } // namespace WebCore | 206 } // namespace WebCore |
OLD | NEW |