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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 if (info.Length() < 1) | 231 if (info.Length() < 1) |
232 return; | 232 return; |
233 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 233 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
234 if (selector.isEmpty()) | 234 if (selector.isEmpty()) |
235 return; | 235 return; |
236 Node* node = secondArgumentAsNode(info); | 236 Node* node = secondArgumentAsNode(info); |
237 if (!node || !node->isContainerNode()) | 237 if (!node || !node->isContainerNode()) |
238 return; | 238 return; |
239 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); | 239 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); |
240 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); | 240 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); |
241 if (exceptionState.throwIfNeeded()) | 241 if (exceptionState.hadException()) |
242 return; | 242 return; |
243 if (element) | 243 if (element) |
244 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); | 244 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); |
245 else | 245 else |
246 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); | 246 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); |
247 } | 247 } |
248 | 248 |
249 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) | 249 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) |
250 { | 250 { |
251 if (info.Length() < 1) | 251 if (info.Length() < 1) |
252 return; | 252 return; |
253 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 253 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
254 if (selector.isEmpty()) | 254 if (selector.isEmpty()) |
255 return; | 255 return; |
256 Node* node = secondArgumentAsNode(info); | 256 Node* node = secondArgumentAsNode(info); |
257 if (!node || !node->isContainerNode()) | 257 if (!node || !node->isContainerNode()) |
258 return; | 258 return; |
259 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 259 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
260 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. | 260 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. |
261 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); | 261 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); |
262 if (exceptionState.throwIfNeeded() || !elementList) | 262 if (exceptionState.hadException() || !elementList) |
263 return; | 263 return; |
264 v8::Isolate* isolate = info.GetIsolate(); | 264 v8::Isolate* isolate = info.GetIsolate(); |
265 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 265 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
266 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); | 266 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); |
267 for (size_t i = 0; i < elementList->length(); ++i) { | 267 for (size_t i = 0; i < elementList->length(); ++i) { |
268 Element* element = elementList->item(i); | 268 Element* element = elementList->item(i); |
269 if (!nodes->Set(context, i, toV8(element, info.Holder(), info.GetIsolate
())).FromMaybe(false)) | 269 if (!nodes->Set(context, i, toV8(element, info.Holder(), info.GetIsolate
())).FromMaybe(false)) |
270 return; | 270 return; |
271 } | 271 } |
272 info.GetReturnValue().Set(nodes); | 272 info.GetReturnValue().Set(nodes); |
273 } | 273 } |
274 | 274 |
275 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) | 275 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
276 { | 276 { |
277 if (info.Length() < 1) | 277 if (info.Length() < 1) |
278 return; | 278 return; |
279 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 279 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
280 if (selector.isEmpty()) | 280 if (selector.isEmpty()) |
281 return; | 281 return; |
282 Node* node = secondArgumentAsNode(info); | 282 Node* node = secondArgumentAsNode(info); |
283 if (!node || !node->isContainerNode()) | 283 if (!node || !node->isContainerNode()) |
284 return; | 284 return; |
285 | 285 |
286 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 286 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
287 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::ANY_TYPE, ScriptValue(), exceptionState); | 287 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::ANY_TYPE, ScriptValue(), exceptionState); |
288 if (exceptionState.throwIfNeeded() || !result) | 288 if (exceptionState.hadException() || !result) |
289 return; | 289 return; |
290 if (result->resultType() == XPathResult::NUMBER_TYPE) { | 290 if (result->resultType() == XPathResult::NUMBER_TYPE) { |
291 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); | 291 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); |
292 } else if (result->resultType() == XPathResult::STRING_TYPE) { | 292 } else if (result->resultType() == XPathResult::STRING_TYPE) { |
293 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); | 293 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); |
294 } else if (result->resultType() == XPathResult::BOOLEAN_TYPE) { | 294 } else if (result->resultType() == XPathResult::BOOLEAN_TYPE) { |
295 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); | 295 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); |
296 } else { | 296 } else { |
297 v8::Isolate* isolate = info.GetIsolate(); | 297 v8::Isolate* isolate = info.GetIsolate(); |
298 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 298 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
299 v8::Local<v8::Array> nodes = v8::Array::New(isolate); | 299 v8::Local<v8::Array> nodes = v8::Array::New(isolate); |
300 size_t index = 0; | 300 size_t index = 0; |
301 while (Node* node = result->iterateNext(exceptionState)) { | 301 while (Node* node = result->iterateNext(exceptionState)) { |
302 if (exceptionState.throwIfNeeded()) | 302 if (exceptionState.hadException()) |
303 return; | 303 return; |
304 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) | 304 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) |
305 return; | 305 return; |
306 } | 306 } |
307 info.GetReturnValue().Set(nodes); | 307 info.GetReturnValue().Set(nodes); |
308 } | 308 } |
309 exceptionState.throwIfNeeded(); | |
310 } | 309 } |
311 | 310 |
312 } // namespace blink | 311 } // namespace blink |
OLD | NEW |