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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (info.Length() < 1) | 273 if (info.Length() < 1) |
274 return; | 274 return; |
275 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 275 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
276 if (selector.isEmpty()) | 276 if (selector.isEmpty()) |
277 return; | 277 return; |
278 Node* node = secondArgumentAsNode(info); | 278 Node* node = secondArgumentAsNode(info); |
279 if (!node || !node->isContainerNode()) | 279 if (!node || !node->isContainerNode()) |
280 return; | 280 return; |
281 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); | 281 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$", "Comman
dLineAPI", info.Holder(), info.GetIsolate()); |
282 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); | 282 Element* element = toContainerNode(node)->querySelector(AtomicString(selecto
r), exceptionState); |
283 if (exceptionState.throwIfNeeded()) | 283 if (exceptionState.hadException()) |
284 return; | 284 return; |
285 if (element) | 285 if (element) |
286 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); | 286 info.GetReturnValue().Set(toV8(element, info.Holder(), info.GetIsolate()
)); |
287 else | 287 else |
288 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); | 288 info.GetReturnValue().Set(v8::Null(info.GetIsolate())); |
289 } | 289 } |
290 | 290 |
291 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) | 291 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo
<v8::Value>& info) |
292 { | 292 { |
293 if (info.Length() < 1) | 293 if (info.Length() < 1) |
294 return; | 294 return; |
295 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 295 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
296 if (selector.isEmpty()) | 296 if (selector.isEmpty()) |
297 return; | 297 return; |
298 Node* node = secondArgumentAsNode(info); | 298 Node* node = secondArgumentAsNode(info); |
299 if (!node || !node->isContainerNode()) | 299 if (!node || !node->isContainerNode()) |
300 return; | 300 return; |
301 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 301 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
302 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. | 302 // toV8(elementList) doesn't work here, since we need a proper Array instanc
e, not NodeList. |
303 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); | 303 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato
micString(selector), exceptionState); |
304 if (exceptionState.throwIfNeeded() || !elementList) | 304 if (exceptionState.hadException() || !elementList) |
305 return; | 305 return; |
306 v8::Isolate* isolate = info.GetIsolate(); | 306 v8::Isolate* isolate = info.GetIsolate(); |
307 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 307 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
308 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); | 308 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length()); |
309 for (size_t i = 0; i < elementList->length(); ++i) { | 309 for (size_t i = 0; i < elementList->length(); ++i) { |
310 Element* element = elementList->item(i); | 310 Element* element = elementList->item(i); |
311 if (!nodes->Set(context, i, toV8(element, info.Holder(), info.GetIsolate
())).FromMaybe(false)) | 311 if (!nodes->Set(context, i, toV8(element, info.Holder(), info.GetIsolate
())).FromMaybe(false)) |
312 return; | 312 return; |
313 } | 313 } |
314 info.GetReturnValue().Set(nodes); | 314 info.GetReturnValue().Set(nodes); |
315 } | 315 } |
316 | 316 |
317 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) | 317 void MainThreadDebugger::xpathSelectorCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
318 { | 318 { |
319 if (info.Length() < 1) | 319 if (info.Length() < 1) |
320 return; | 320 return; |
321 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); | 321 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); |
322 if (selector.isEmpty()) | 322 if (selector.isEmpty()) |
323 return; | 323 return; |
324 Node* node = secondArgumentAsNode(info); | 324 Node* node = secondArgumentAsNode(info); |
325 if (!node || !node->isContainerNode()) | 325 if (!node || !node->isContainerNode()) |
326 return; | 326 return; |
327 | 327 |
328 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); | 328 ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "Comma
ndLineAPI", info.Holder(), info.GetIsolate()); |
329 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::ANY_TYPE, ScriptValue(), exceptionState); | 329 XPathResult* result = XPathEvaluator::create()->evaluate(selector, node, nul
lptr, XPathResult::ANY_TYPE, ScriptValue(), exceptionState); |
330 if (exceptionState.throwIfNeeded() || !result) | 330 if (exceptionState.hadException() || !result) |
331 return; | 331 return; |
332 if (result->resultType() == XPathResult::NUMBER_TYPE) { | 332 if (result->resultType() == XPathResult::NUMBER_TYPE) { |
333 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); | 333 info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info
.Holder(), info.GetIsolate())); |
334 } else if (result->resultType() == XPathResult::STRING_TYPE) { | 334 } else if (result->resultType() == XPathResult::STRING_TYPE) { |
335 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); | 335 info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info
.Holder(), info.GetIsolate())); |
336 } else if (result->resultType() == XPathResult::BOOLEAN_TYPE) { | 336 } else if (result->resultType() == XPathResult::BOOLEAN_TYPE) { |
337 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); | 337 info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), inf
o.Holder(), info.GetIsolate())); |
338 } else { | 338 } else { |
339 v8::Isolate* isolate = info.GetIsolate(); | 339 v8::Isolate* isolate = info.GetIsolate(); |
340 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 340 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
341 v8::Local<v8::Array> nodes = v8::Array::New(isolate); | 341 v8::Local<v8::Array> nodes = v8::Array::New(isolate); |
342 size_t index = 0; | 342 size_t index = 0; |
343 while (Node* node = result->iterateNext(exceptionState)) { | 343 while (Node* node = result->iterateNext(exceptionState)) { |
344 if (exceptionState.throwIfNeeded()) | 344 if (exceptionState.hadException()) |
345 return; | 345 return; |
346 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) | 346 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) |
347 return; | 347 return; |
348 } | 348 } |
349 info.GetReturnValue().Set(nodes); | 349 info.GetReturnValue().Set(nodes); |
350 } | 350 } |
351 exceptionState.throwIfNeeded(); | |
352 } | 351 } |
353 | 352 |
354 } // namespace blink | 353 } // namespace blink |
OLD | NEW |