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

Side by Side Diff: Source/bindings/core/v8/NPV8Object.cpp

Issue 1067763002: bindings: Use Maybe version of Get in bindings/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/ArrayValue.cpp ('k') | Source/bindings/core/v8/ScriptController.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved. 3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved.
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 // FIXME: should use the plugin's owner frame as the security context. 251 // FIXME: should use the plugin's owner frame as the security context.
252 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); 252 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject);
253 if (!scriptState) 253 if (!scriptState)
254 return false; 254 return false;
255 255
256 ScriptState::Scope scope(scriptState); 256 ScriptState::Scope scope(scriptState);
257 ExceptionCatcher exceptionCatcher; 257 ExceptionCatcher exceptionCatcher;
258 258
259 v8::Local<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpObj ect->v8Object); 259 v8::Local<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpObj ect->v8Object);
260 v8::Local<v8::Value> functionObject = v8Object->Get(v8AtomicString(isolate, identifier->value.string)); 260 v8::Local<v8::Value> functionObject;
261 if (functionObject.IsEmpty() || functionObject->IsNull()) { 261 if (!v8Object->Get(scriptState->context(), v8AtomicString(scriptState->isola te(), identifier->value.string)).ToLocal(&functionObject) || functionObject->IsN ull()) {
262 NULL_TO_NPVARIANT(*result); 262 NULL_TO_NPVARIANT(*result);
263 return false; 263 return false;
264 } 264 }
265 if (functionObject->IsUndefined()) { 265 if (functionObject->IsUndefined()) {
266 VOID_TO_NPVARIANT(*result); 266 VOID_TO_NPVARIANT(*result);
267 return false; 267 return false;
268 } 268 }
269 269
270 LocalFrame* frame = v8NpObject->rootObject->frame(); 270 LocalFrame* frame = v8NpObject->rootObject->frame();
271 ASSERT(frame); 271 ASSERT(frame);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { 390 if (V8NPObject* object = npObjectToV8NPObject(npObject)) {
391 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 391 v8::Isolate* isolate = v8::Isolate::GetCurrent();
392 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); 392 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject);
393 if (!scriptState) 393 if (!scriptState)
394 return false; 394 return false;
395 395
396 ScriptState::Scope scope(scriptState); 396 ScriptState::Scope scope(scriptState);
397 ExceptionCatcher exceptionCatcher; 397 ExceptionCatcher exceptionCatcher;
398 398
399 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object); 399 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object);
400 v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(isol ate, propertyName)); 400 v8::Local<v8::Value> v8result;
401 401 if (!obj->Get(scriptState->context(), npIdentifierToV8Identifier(scriptS tate->isolate(), propertyName)).ToLocal(&v8result))
402 if (v8result.IsEmpty())
403 return false; 402 return false;
404 403
405 convertV8ObjectToNPVariant(isolate, v8result, npObject, result); 404 convertV8ObjectToNPVariant(isolate, v8result, npObject, result);
406 return true; 405 return true;
407 } 406 }
408 407
409 if (npObject->_class->hasProperty && npObject->_class->getProperty) { 408 if (npObject->_class->hasProperty && npObject->_class->getProperty) {
410 if (npObject->_class->hasProperty(npObject, propertyName)) 409 if (npObject->_class->hasProperty(npObject, propertyName))
411 return npObject->_class->getProperty(npObject, propertyName, result) ; 410 return npObject->_class->getProperty(npObject, propertyName, result) ;
412 } 411 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 490
492 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { 491 if (V8NPObject* object = npObjectToV8NPObject(npObject)) {
493 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 492 v8::Isolate* isolate = v8::Isolate::GetCurrent();
494 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); 493 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject);
495 if (!scriptState) 494 if (!scriptState)
496 return false; 495 return false;
497 ScriptState::Scope scope(scriptState); 496 ScriptState::Scope scope(scriptState);
498 ExceptionCatcher exceptionCatcher; 497 ExceptionCatcher exceptionCatcher;
499 498
500 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object); 499 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object);
501 v8::Local<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(isolate, methodName)); 500 v8::Local<v8::Value> prop;
501 if (!obj->Get(scriptState->context(), npIdentifierToV8Identifier(scriptS tate->isolate(), methodName)).ToLocal(&prop))
502 return false;
502 return prop->IsFunction(); 503 return prop->IsFunction();
503 } 504 }
504 505
505 if (npObject->_class->hasMethod) 506 if (npObject->_class->hasMethod)
506 return npObject->_class->hasMethod(npObject, methodName); 507 return npObject->_class->hasMethod(npObject, methodName);
507 return false; 508 return false;
508 } 509 }
509 510
510 void _NPN_SetException(NPObject* npObject, const NPUTF8 *message) 511 void _NPN_SetException(NPObject* npObject, const NPUTF8 *message)
511 { 512 {
(...skipping 14 matching lines...) Expand all
526 527
527 V8ThrowException::throwGeneralError(isolate, message); 528 V8ThrowException::throwGeneralError(isolate, message);
528 } 529 }
529 530
530 bool _NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint 32_t* count) 531 bool _NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint 32_t* count)
531 { 532 {
532 if (!npObject) 533 if (!npObject)
533 return false; 534 return false;
534 535
535 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { 536 if (V8NPObject* object = npObjectToV8NPObject(npObject)) {
536 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 537 ScriptState* scriptState = mainWorldScriptState(v8::Isolate::GetCurrent( ), npp, npObject);
537 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject);
538 if (!scriptState) 538 if (!scriptState)
539 return false; 539 return false;
540 ScriptState::Scope scope(scriptState); 540 ScriptState::Scope scope(scriptState);
541 ExceptionCatcher exceptionCatcher; 541 ExceptionCatcher exceptionCatcher;
542 542
543 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object); 543 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(scriptState->isol ate(), object->v8Object);
544 544
545 // FIXME: http://b/issue?id=1210340: Use a v8::Object::Keys() method whe n it exists, instead of evaluating javascript. 545 // FIXME: http://b/issue?id=1210340: Use a v8::Object::Keys() method whe n it exists, instead of evaluating javascript.
546 546
547 // FIXME: Figure out how to cache this helper function. Run a helper fu nction that collects the properties 547 // FIXME: Figure out how to cache this helper function. Run a helper fu nction that collects the properties
548 // on the object into an array. 548 // on the object into an array.
549 const char enumeratorCode[] = 549 const char enumeratorCode[] =
550 "(function (obj) {" 550 "(function (obj) {"
551 " var props = [];" 551 " var props = [];"
552 " for (var prop in obj) {" 552 " for (var prop in obj) {"
553 " props[props.length] = prop;" 553 " props[props.length] = prop;"
554 " }" 554 " }"
555 " return props;" 555 " return props;"
556 "});"; 556 "});";
557 v8::Local<v8::String> source = v8AtomicString(isolate, enumeratorCode); 557 v8::Local<v8::String> source = v8AtomicString(scriptState->isolate(), en umeratorCode);
558 v8::Local<v8::Value> result; 558 v8::Local<v8::Value> result;
559 if (!V8ScriptRunner::compileAndRunInternalScript(source, isolate).ToLoca l(&result)) 559 if (!V8ScriptRunner::compileAndRunInternalScript(source, scriptState->is olate()).ToLocal(&result))
560 return false; 560 return false;
561 ASSERT(result->IsFunction()); 561 ASSERT(result->IsFunction());
562 v8::Local<v8::Function> enumerator = v8::Local<v8::Function>::Cast(resul t); 562 v8::Local<v8::Function> enumerator = v8::Local<v8::Function>::Cast(resul t);
563 v8::Local<v8::Value> argv[] = { obj }; 563 v8::Local<v8::Value> argv[] = { obj };
564 v8::Local<v8::Value> propsObj; 564 v8::Local<v8::Value> propsObj;
565 if (!V8ScriptRunner::callInternalFunction(enumerator, v8::Local<v8::Obje ct>::Cast(result), WTF_ARRAY_LENGTH(argv), argv, isolate).ToLocal(&propsObj)) 565 if (!V8ScriptRunner::callInternalFunction(enumerator, v8::Local<v8::Obje ct>::Cast(result), WTF_ARRAY_LENGTH(argv), argv, scriptState->isolate()).ToLocal (&propsObj))
566 return false; 566 return false;
567 567
568 // Convert the results into an array of NPIdentifiers. 568 // Convert the results into an array of NPIdentifiers.
569 v8::Local<v8::Array> props = v8::Local<v8::Array>::Cast(propsObj); 569 v8::Local<v8::Array> props = v8::Local<v8::Array>::Cast(propsObj);
570 *count = props->Length(); 570 *count = props->Length();
571 *identifier = static_cast<NPIdentifier*>(calloc(*count, sizeof(NPIdentif ier))); 571 *identifier = static_cast<NPIdentifier*>(calloc(*count, sizeof(NPIdentif ier)));
572 for (uint32_t i = 0; i < *count; ++i) { 572 for (uint32_t i = 0; i < *count; ++i) {
573 v8::Local<v8::Value> name = props->Get(v8::Integer::New(isolate, i)) ; 573 v8::Local<v8::Value> name;
574 if (!props->Get(scriptState->context(), v8::Integer::New(scriptState ->isolate(), i)).ToLocal(&name))
575 return false;
574 (*identifier)[i] = getStringIdentifier(v8::Local<v8::String>::Cast(n ame)); 576 (*identifier)[i] = getStringIdentifier(v8::Local<v8::String>::Cast(n ame));
575 } 577 }
576 return true; 578 return true;
577 } 579 }
578 580
579 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class-> enumerate) 581 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class-> enumerate)
580 return npObject->_class->enumerate(npObject, identifier, count); 582 return npObject->_class->enumerate(npObject, identifier, count);
581 583
582 return false; 584 return false;
583 } 585 }
584 586
585 bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin t32_t argumentCount, NPVariant* result) 587 bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin t32_t argumentCount, NPVariant* result)
586 { 588 {
587 if (!npObject) 589 if (!npObject)
588 return false; 590 return false;
589 591
590 v8::Isolate* isolate = v8::Isolate::GetCurrent();
591
592 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { 592 if (V8NPObject* object = npObjectToV8NPObject(npObject)) {
593 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); 593 ScriptState* scriptState = mainWorldScriptState(v8::Isolate::GetCurrent( ), npp, npObject);
594 if (!scriptState) 594 if (!scriptState)
595 return false; 595 return false;
596 ScriptState::Scope scope(scriptState); 596 ScriptState::Scope scope(scriptState);
597 ExceptionCatcher exceptionCatcher; 597 ExceptionCatcher exceptionCatcher;
598 598
599 // Lookup the constructor function. 599 // Lookup the constructor function.
600 v8::Local<v8::Object> ctorObj = v8::Local<v8::Object>::New(isolate, obje ct->v8Object); 600 v8::Local<v8::Object> ctorObj = v8::Local<v8::Object>::New(scriptState-> isolate(), object->v8Object);
601 if (!ctorObj->IsFunction()) 601 if (!ctorObj->IsFunction())
602 return false; 602 return false;
603 603
604 // Call the constructor. 604 // Call the constructor.
605 v8::Local<v8::Value> resultObject; 605 v8::Local<v8::Value> resultObject;
606 v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorObj); 606 v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorObj);
607 if (!ctor->IsNull()) { 607 if (!ctor->IsNull()) {
608 LocalFrame* frame = object->rootObject->frame(); 608 LocalFrame* frame = object->rootObject->frame();
609 ASSERT(frame); 609 ASSERT(frame);
610 OwnPtr<v8::Local<v8::Value>[]> argv = createValueListFromVariantArgs (arguments, argumentCount, npObject, isolate); 610 OwnPtr<v8::Local<v8::Value>[]> argv = createValueListFromVariantArgs (arguments, argumentCount, npObject, scriptState->isolate());
611 resultObject = V8ObjectConstructor::newInstanceInDocument(isolate, c tor, argumentCount, argv.get(), frame ? frame->document() : 0); 611 resultObject = V8ObjectConstructor::newInstanceInDocument(scriptStat e->isolate(), ctor, argumentCount, argv.get(), frame ? frame->document() : 0);
612 } 612 }
613 613
614 if (resultObject.IsEmpty()) 614 if (resultObject.IsEmpty())
615 return false; 615 return false;
616 616
617 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); 617 convertV8ObjectToNPVariant(scriptState->isolate(), resultObject, npObjec t, result);
618 return true; 618 return true;
619 } 619 }
620 620
621 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct) 621 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct)
622 return npObject->_class->construct(npObject, arguments, argumentCount, r esult); 622 return npObject->_class->construct(npObject, arguments, argumentCount, r esult);
623 623
624 return false; 624 return false;
625 } 625 }
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ArrayValue.cpp ('k') | Source/bindings/core/v8/ScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698