OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
Yuki
2015/04/07 07:37:57
Can you remove this line?
bashi
2015/04/07 08:47:01
Done.
| |
537 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 538 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
538 if (!scriptState) | 539 if (!scriptState) |
539 return false; | 540 return false; |
540 ScriptState::Scope scope(scriptState); | 541 ScriptState::Scope scope(scriptState); |
541 ExceptionCatcher exceptionCatcher; | 542 ExceptionCatcher exceptionCatcher; |
542 | 543 |
543 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-> v8Object); | 544 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(scriptState->isol ate(), object->v8Object); |
544 | 545 |
545 // FIXME: http://b/issue?id=1210340: Use a v8::Object::Keys() method whe n it exists, instead of evaluating javascript. | 546 // FIXME: http://b/issue?id=1210340: Use a v8::Object::Keys() method whe n it exists, instead of evaluating javascript. |
546 | 547 |
547 // FIXME: Figure out how to cache this helper function. Run a helper fu nction that collects the properties | 548 // 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. | 549 // on the object into an array. |
549 const char enumeratorCode[] = | 550 const char enumeratorCode[] = |
550 "(function (obj) {" | 551 "(function (obj) {" |
551 " var props = [];" | 552 " var props = [];" |
552 " for (var prop in obj) {" | 553 " for (var prop in obj) {" |
553 " props[props.length] = prop;" | 554 " props[props.length] = prop;" |
554 " }" | 555 " }" |
555 " return props;" | 556 " return props;" |
556 "});"; | 557 "});"; |
557 v8::Local<v8::String> source = v8AtomicString(isolate, enumeratorCode); | 558 v8::Local<v8::String> source = v8AtomicString(scriptState->isolate(), en umeratorCode); |
558 v8::Local<v8::Value> result; | 559 v8::Local<v8::Value> result; |
559 if (!V8ScriptRunner::compileAndRunInternalScript(source, isolate).ToLoca l(&result)) | 560 if (!V8ScriptRunner::compileAndRunInternalScript(source, scriptState->is olate()).ToLocal(&result)) |
560 return false; | 561 return false; |
561 ASSERT(result->IsFunction()); | 562 ASSERT(result->IsFunction()); |
562 v8::Local<v8::Function> enumerator = v8::Local<v8::Function>::Cast(resul t); | 563 v8::Local<v8::Function> enumerator = v8::Local<v8::Function>::Cast(resul t); |
563 v8::Local<v8::Value> argv[] = { obj }; | 564 v8::Local<v8::Value> argv[] = { obj }; |
564 v8::Local<v8::Value> propsObj; | 565 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)) | 566 if (!V8ScriptRunner::callInternalFunction(enumerator, v8::Local<v8::Obje ct>::Cast(result), WTF_ARRAY_LENGTH(argv), argv, scriptState->isolate()).ToLocal (&propsObj)) |
566 return false; | 567 return false; |
567 | 568 |
568 // Convert the results into an array of NPIdentifiers. | 569 // Convert the results into an array of NPIdentifiers. |
569 v8::Local<v8::Array> props = v8::Local<v8::Array>::Cast(propsObj); | 570 v8::Local<v8::Array> props = v8::Local<v8::Array>::Cast(propsObj); |
570 *count = props->Length(); | 571 *count = props->Length(); |
571 *identifier = static_cast<NPIdentifier*>(calloc(*count, sizeof(NPIdentif ier))); | 572 *identifier = static_cast<NPIdentifier*>(calloc(*count, sizeof(NPIdentif ier))); |
572 for (uint32_t i = 0; i < *count; ++i) { | 573 for (uint32_t i = 0; i < *count; ++i) { |
573 v8::Local<v8::Value> name = props->Get(v8::Integer::New(isolate, i)) ; | 574 v8::Local<v8::Value> name; |
575 if (!props->Get(scriptState->context(), v8::Integer::New(scriptState ->isolate(), i)).ToLocal(&name)) | |
576 return false; | |
574 (*identifier)[i] = getStringIdentifier(v8::Local<v8::String>::Cast(n ame)); | 577 (*identifier)[i] = getStringIdentifier(v8::Local<v8::String>::Cast(n ame)); |
575 } | 578 } |
576 return true; | 579 return true; |
577 } | 580 } |
578 | 581 |
579 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class-> enumerate) | 582 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class-> enumerate) |
580 return npObject->_class->enumerate(npObject, identifier, count); | 583 return npObject->_class->enumerate(npObject, identifier, count); |
581 | 584 |
582 return false; | 585 return false; |
583 } | 586 } |
584 | 587 |
585 bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin t32_t argumentCount, NPVariant* result) | 588 bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin t32_t argumentCount, NPVariant* result) |
586 { | 589 { |
587 if (!npObject) | 590 if (!npObject) |
588 return false; | 591 return false; |
589 | 592 |
590 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 593 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
Yuki
2015/04/07 07:37:57
Can you remove this line?
bashi
2015/04/07 08:47:01
Done.
| |
591 | 594 |
592 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 595 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
593 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 596 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
594 if (!scriptState) | 597 if (!scriptState) |
595 return false; | 598 return false; |
596 ScriptState::Scope scope(scriptState); | 599 ScriptState::Scope scope(scriptState); |
597 ExceptionCatcher exceptionCatcher; | 600 ExceptionCatcher exceptionCatcher; |
598 | 601 |
599 // Lookup the constructor function. | 602 // Lookup the constructor function. |
600 v8::Local<v8::Object> ctorObj = v8::Local<v8::Object>::New(isolate, obje ct->v8Object); | 603 v8::Local<v8::Object> ctorObj = v8::Local<v8::Object>::New(scriptState-> isolate(), object->v8Object); |
601 if (!ctorObj->IsFunction()) | 604 if (!ctorObj->IsFunction()) |
602 return false; | 605 return false; |
603 | 606 |
604 // Call the constructor. | 607 // Call the constructor. |
605 v8::Local<v8::Value> resultObject; | 608 v8::Local<v8::Value> resultObject; |
606 v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorObj); | 609 v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorObj); |
607 if (!ctor->IsNull()) { | 610 if (!ctor->IsNull()) { |
608 LocalFrame* frame = object->rootObject->frame(); | 611 LocalFrame* frame = object->rootObject->frame(); |
609 ASSERT(frame); | 612 ASSERT(frame); |
610 OwnPtr<v8::Local<v8::Value>[]> argv = createValueListFromVariantArgs (arguments, argumentCount, npObject, isolate); | 613 OwnPtr<v8::Local<v8::Value>[]> argv = createValueListFromVariantArgs (arguments, argumentCount, npObject, isolate); |
611 resultObject = V8ObjectConstructor::newInstanceInDocument(isolate, c tor, argumentCount, argv.get(), frame ? frame->document() : 0); | 614 resultObject = V8ObjectConstructor::newInstanceInDocument(isolate, c tor, argumentCount, argv.get(), frame ? frame->document() : 0); |
612 } | 615 } |
613 | 616 |
614 if (resultObject.IsEmpty()) | 617 if (resultObject.IsEmpty()) |
615 return false; | 618 return false; |
616 | 619 |
617 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); | 620 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); |
618 return true; | 621 return true; |
619 } | 622 } |
620 | 623 |
621 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct) | 624 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct) |
622 return npObject->_class->construct(npObject, arguments, argumentCount, r esult); | 625 return npObject->_class->construct(npObject, arguments, argumentCount, r esult); |
623 | 626 |
624 return false; | 627 return false; |
625 } | 628 } |
OLD | NEW |