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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 if (info.Length() < 1) | 338 if (info.Length() < 1) |
339 return; | 339 return; |
340 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 340 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
341 if (selector.isEmpty()) | 341 if (selector.isEmpty()) |
342 return; | 342 return; |
343 Node* node = secondArgumentAsNode(info); | 343 Node* node = secondArgumentAsNode(info); |
344 if (!node || !node->isContainerNode()) | 344 if (!node || !node->isContainerNode()) |
345 return; | 345 return; |
346 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); | 346 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); |
347 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); | 347 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); |
348 if (exceptionState.throwIfNeeded()) | 348 if (exceptionState.hadException()) |
349 return; | 349 return; |
350 if (element) | 350 if (element) |
351 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); | 351 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); |
352 else | 352 else |
353 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); | 353 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); |
354 } | 354 } |
355 | 355 |
356 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) | 356 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) |
357 { | 357 { |
358 if (info.Length() < 1) | 358 if (info.Length() < 1) |
359 return; | 359 return; |
360 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 360 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
361 if (selector.isEmpty()) | 361 if (selector.isEmpty()) |
362 return; | 362 return; |
363 Node* node = secondArgumentAsNode(info); | 363 Node* node = secondArgumentAsNode(info); |
364 if (!node || !node->isContainerNode()) | 364 if (!node || !node->isContainerNode()) |
365 return; | 365 return; |
366 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 366 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
367 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. | 367 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. |
368 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); | 368 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); |
369 if (exceptionState.throwIfNeeded() || !elementList) | 369 if (exceptionState.hadException() || !elementList) |
370 return; | 370 return; |
371 v8::Isolate* isolate = info.GetIsolate(); | 371 v8::Isolate* isolate = info.GetIsolate(); |
372 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 372 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
373 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); | 373 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); |
374 for (size_t i = 0; i < elementList->length(); ++i) { | 374 for (size_t i = 0; i < elementList->length(); ++i) { |
375 Element* element = elementList->item(i); | 375 Element* element = elementList->item(i); |
376 if (!createDataPropertyInArray(context, nodes, i, toV8(element, info.Hol
der(), info.GetIsolate())).FromMaybe(false)) | 376 if (!createDataPropertyInArray(context, nodes, i, toV8(element, info.Hol
der(), info.GetIsolate())).FromMaybe(false)) |
377 return; | 377 return; |
378 } | 378 } |
379 info.GetReturnValue().Set(nodes); | 379 info.GetReturnValue().Set(nodes); |
380 } | 380 } |
381 | 381 |
382 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) | 382 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
383 { | 383 { |
384 if (info.Length() < 1) | 384 if (info.Length() < 1) |
385 return; | 385 return; |
386 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 386 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
387 if (selector.isEmpty()) | 387 if (selector.isEmpty()) |
388 return; | 388 return; |
389 Node* node = secondArgumentAsNode(info); | 389 Node* node = secondArgumentAsNode(info); |
390 if (!node || !node->isContainerNode()) | 390 if (!node || !node->isContainerNode()) |
391 return; | 391 return; |
392 | 392 |
393 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 393 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
394 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::kAnyType, ScriptValue(), exceptionState); | 394 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::kAnyType, ScriptValue(), exceptionState); |
395 if (exceptionState.throwIfNeeded() || !result) | 395 if (exceptionState.hadException() || !result) |
396 return; | 396 return; |
397 if (result->resultType() == XPathResult::kNumberType) { | 397 if (result->resultType() == XPathResult::kNumberType) { |
398 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); | 398 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); |
399 } else if (result->resultType() == XPathResult::kStringType) { | 399 } else if (result->resultType() == XPathResult::kStringType) { |
400 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); | 400 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); |
401 } else if (result->resultType() == XPathResult::kBooleanType) { | 401 } else if (result->resultType() == XPathResult::kBooleanType) { |
402 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); | 402 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); |
403 } else { | 403 } else { |
404 v8::Isolate* isolate = info.GetIsolate(); | 404 v8::Isolate* isolate = info.GetIsolate(); |
405 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 405 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
406 v8::Local<v8::Array> nodes = v8::Array::New(isolate); | 406 v8::Local<v8::Array> nodes = v8::Array::New(isolate); |
407 size_t index = 0; | 407 size_t index = 0; |
408 while (Node* node = result->iterateNext(exceptionState)) { | 408 while (Node* node = result->iterateNext(exceptionState)) { |
409 if (exceptionState.throwIfNeeded()) | 409 if (exceptionState.hadException()) |
410 return; | 410 return; |
411 if (!createDataPropertyInArray(context, nodes, index++, toV8(node, i
nfo.Holder(), info.GetIsolate())).FromMaybe(false)) | 411 if (!createDataPropertyInArray(context, nodes, index++, toV8(node, i
nfo.Holder(), info.GetIsolate())).FromMaybe(false)) |
412 return; | 412 return; |
413 } | 413 } |
414 info.GetReturnValue().Set(nodes); | 414 info.GetReturnValue().Set(nodes); |
415 } | 415 } |
416 exceptionState.throwIfNeeded(); | |
417 } | 416 } |
418 | 417 |
419 } // namespace blink | 418 } // namespace blink |
OLD | NEW |