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

Side by Side Diff: fxjs/fxjs_v8.cpp

Issue 2637503002: Tidy FXJS_V8, backfill tests. (Closed)
Patch Set: rebase Created 3 years, 11 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
« no previous file with comments | « fxjs/fxjs_v8.h ('k') | fxjs/fxjs_v8_embeddertest.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 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fxjs/fxjs_v8.h" 7 #include "fxjs/fxjs_v8.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 if (pObj.IsEmpty()) 589 if (pObj.IsEmpty())
590 return std::vector<CFX_WideString>(); 590 return std::vector<CFX_WideString>();
591 591
592 v8::Local<v8::Array> val; 592 v8::Local<v8::Array> val;
593 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 593 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
594 if (!pObj->GetPropertyNames(context).ToLocal(&val)) 594 if (!pObj->GetPropertyNames(context).ToLocal(&val))
595 return std::vector<CFX_WideString>(); 595 return std::vector<CFX_WideString>();
596 596
597 std::vector<CFX_WideString> result; 597 std::vector<CFX_WideString> result;
598 for (uint32_t i = 0; i < val->Length(); ++i) { 598 for (uint32_t i = 0; i < val->Length(); ++i) {
599 result.push_back(ToString(val->Get(context, i).ToLocalChecked())); 599 result.push_back(ToWideString(val->Get(context, i).ToLocalChecked()));
600 } 600 }
601 601
602 return result; 602 return result;
603 } 603 }
604 604
605 void CFXJS_Engine::PutObjectString(v8::Local<v8::Object> pObj, 605 void CFXJS_Engine::PutObjectProperty(v8::Local<v8::Object> pObj,
606 const CFX_WideString& wsPropertyName, 606 const CFX_WideString& wsPropertyName,
607 const CFX_WideString& wsValue) { 607 v8::Local<v8::Value> pPut) {
608 if (pObj.IsEmpty())
609 return;
610 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
611 WSToJSString(wsValue))
612 .FromJust();
613 }
614
615 void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
616 const CFX_WideString& wsPropertyName,
617 int nValue) {
618 if (pObj.IsEmpty())
619 return;
620 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
621 v8::Int32::New(m_isolate, nValue))
622 .FromJust();
623 }
624
625 void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
626 const CFX_WideString& wsPropertyName,
627 float fValue) {
628 if (pObj.IsEmpty())
629 return;
630 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
631 v8::Number::New(m_isolate, (double)fValue))
632 .FromJust();
633 }
634
635 void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
636 const CFX_WideString& wsPropertyName,
637 double dValue) {
638 if (pObj.IsEmpty())
639 return;
640 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
641 v8::Number::New(m_isolate, (double)dValue))
642 .FromJust();
643 }
644
645 void CFXJS_Engine::PutObjectBoolean(v8::Local<v8::Object> pObj,
646 const CFX_WideString& wsPropertyName,
647 bool bValue) {
648 if (pObj.IsEmpty())
649 return;
650 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
651 v8::Boolean::New(m_isolate, bValue))
652 .FromJust();
653 }
654
655 void CFXJS_Engine::PutObjectObject(v8::Local<v8::Object> pObj,
656 const CFX_WideString& wsPropertyName,
657 v8::Local<v8::Object> pPut) {
658 if (pObj.IsEmpty()) 608 if (pObj.IsEmpty())
659 return; 609 return;
660 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName), pPut) 610 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName), pPut)
661 .FromJust(); 611 .FromJust();
662 } 612 }
663 613
664 void CFXJS_Engine::PutObjectNull(v8::Local<v8::Object> pObj,
665 const CFX_WideString& wsPropertyName) {
666 if (pObj.IsEmpty())
667 return;
668 pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
669 v8::Local<v8::Object>())
670 .FromJust();
671 }
672 614
673 v8::Local<v8::Array> CFXJS_Engine::NewArray() { 615 v8::Local<v8::Array> CFXJS_Engine::NewArray() {
674 return v8::Array::New(m_isolate); 616 return v8::Array::New(m_isolate);
675 } 617 }
676 618
677 unsigned CFXJS_Engine::PutArrayElement(v8::Local<v8::Array> pArray, 619 unsigned CFXJS_Engine::PutArrayElement(v8::Local<v8::Array> pArray,
678 unsigned index, 620 unsigned index,
679 v8::Local<v8::Value> pValue) { 621 v8::Local<v8::Value> pValue) {
680 if (pArray.IsEmpty()) 622 if (pArray.IsEmpty())
681 return 0; 623 return 0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 659 }
718 660
719 v8::Local<v8::Value> CFXJS_Engine::NewNumber(float number) { 661 v8::Local<v8::Value> CFXJS_Engine::NewNumber(float number) {
720 return v8::Number::New(m_isolate, (float)number); 662 return v8::Number::New(m_isolate, (float)number);
721 } 663 }
722 664
723 v8::Local<v8::Value> CFXJS_Engine::NewBoolean(bool b) { 665 v8::Local<v8::Value> CFXJS_Engine::NewBoolean(bool b) {
724 return v8::Boolean::New(m_isolate, b); 666 return v8::Boolean::New(m_isolate, b);
725 } 667 }
726 668
727 v8::Local<v8::Value> CFXJS_Engine::NewString(const wchar_t* str) { 669 v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_WideString& str) {
728 return WSToJSString(str); 670 return WSToJSString(str.c_str());
729 } 671 }
730 672
731 v8::Local<v8::Value> CFXJS_Engine::NewNull() { 673 v8::Local<v8::Value> CFXJS_Engine::NewNull() {
732 return v8::Local<v8::Value>(); 674 return v8::Local<v8::Value>();
733 } 675 }
734 676
735 v8::Local<v8::Date> CFXJS_Engine::NewDate(double d) { 677 v8::Local<v8::Date> CFXJS_Engine::NewDate(double d) {
736 return v8::Date::New(m_isolate->GetCurrentContext(), d) 678 return v8::Date::New(m_isolate->GetCurrentContext(), d)
737 .ToLocalChecked() 679 .ToLocalChecked()
738 .As<v8::Date>(); 680 .As<v8::Date>();
739 } 681 }
740 682
741 int CFXJS_Engine::ToInt32(v8::Local<v8::Value> pValue) { 683 int CFXJS_Engine::ToInt32(v8::Local<v8::Value> pValue) {
742 if (pValue.IsEmpty()) 684 if (pValue.IsEmpty())
743 return 0; 685 return 0;
744 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 686 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
745 return pValue->ToInt32(context).ToLocalChecked()->Value(); 687 return pValue->ToInt32(context).ToLocalChecked()->Value();
746 } 688 }
747 689
748 bool CFXJS_Engine::ToBoolean(v8::Local<v8::Value> pValue) { 690 bool CFXJS_Engine::ToBoolean(v8::Local<v8::Value> pValue) {
749 if (pValue.IsEmpty()) 691 if (pValue.IsEmpty())
750 return false; 692 return false;
751 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 693 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
752 return pValue->ToBoolean(context).ToLocalChecked()->Value(); 694 return pValue->ToBoolean(context).ToLocalChecked()->Value();
753 } 695 }
754 696
755 double CFXJS_Engine::ToNumber(v8::Local<v8::Value> pValue) { 697 double CFXJS_Engine::ToDouble(v8::Local<v8::Value> pValue) {
756 if (pValue.IsEmpty()) 698 if (pValue.IsEmpty())
757 return 0.0; 699 return 0.0;
758 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 700 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
759 return pValue->ToNumber(context).ToLocalChecked()->Value(); 701 return pValue->ToNumber(context).ToLocalChecked()->Value();
760 } 702 }
761 703
704 CFX_WideString CFXJS_Engine::ToWideString(v8::Local<v8::Value> pValue) {
705 if (pValue.IsEmpty())
706 return CFX_WideString();
707 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
708 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
709 return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length()));
710 }
711
762 v8::Local<v8::Object> CFXJS_Engine::ToObject(v8::Local<v8::Value> pValue) { 712 v8::Local<v8::Object> CFXJS_Engine::ToObject(v8::Local<v8::Value> pValue) {
763 if (pValue.IsEmpty()) 713 if (pValue.IsEmpty() || !pValue->IsObject())
764 return v8::Local<v8::Object>(); 714 return v8::Local<v8::Object>();
765 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 715 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
766 return pValue->ToObject(context).ToLocalChecked(); 716 return pValue->ToObject(context).ToLocalChecked();
767 } 717 }
768 718
769 CFX_WideString CFXJS_Engine::ToString(v8::Local<v8::Value> pValue) {
770 if (pValue.IsEmpty())
771 return L"";
772 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
773 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
774 return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length()));
775 }
776
777 v8::Local<v8::Array> CFXJS_Engine::ToArray(v8::Local<v8::Value> pValue) { 719 v8::Local<v8::Array> CFXJS_Engine::ToArray(v8::Local<v8::Value> pValue) {
778 if (pValue.IsEmpty()) 720 if (pValue.IsEmpty() || !pValue->IsArray())
779 return v8::Local<v8::Array>(); 721 return v8::Local<v8::Array>();
780 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 722 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
781 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 723 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
782 } 724 }
783 725
784 void CFXJS_Engine::SetConstArray(const CFX_WideString& name, 726 void CFXJS_Engine::SetConstArray(const CFX_WideString& name,
785 v8::Local<v8::Array> array) { 727 v8::Local<v8::Array> array) {
786 m_ConstArrays[name] = v8::Global<v8::Array>(GetIsolate(), array); 728 m_ConstArrays[name] = v8::Global<v8::Array>(GetIsolate(), array);
787 } 729 }
788 730
789 v8::Local<v8::Array> CFXJS_Engine::GetConstArray(const CFX_WideString& name) { 731 v8::Local<v8::Array> CFXJS_Engine::GetConstArray(const CFX_WideString& name) {
790 return v8::Local<v8::Array>::New(GetIsolate(), m_ConstArrays[name]); 732 return v8::Local<v8::Array>::New(GetIsolate(), m_ConstArrays[name]);
791 } 733 }
OLDNEW
« no previous file with comments | « fxjs/fxjs_v8.h ('k') | fxjs/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698