OLD | NEW |
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/include/fxjs_v8.h" | 7 #include "fxjs/include/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 Loading... |
589 v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate, | 589 v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate, |
590 const CFX_WideString& wsPropertyName) { | 590 const CFX_WideString& wsPropertyName) { |
591 CFX_ByteString bs = wsPropertyName.UTF8Encode(); | 591 CFX_ByteString bs = wsPropertyName.UTF8Encode(); |
592 if (!pIsolate) | 592 if (!pIsolate) |
593 pIsolate = v8::Isolate::GetCurrent(); | 593 pIsolate = v8::Isolate::GetCurrent(); |
594 return v8::String::NewFromUtf8(pIsolate, bs.c_str(), | 594 return v8::String::NewFromUtf8(pIsolate, bs.c_str(), |
595 v8::NewStringType::kNormal, bs.GetLength()) | 595 v8::NewStringType::kNormal, bs.GetLength()) |
596 .ToLocalChecked(); | 596 .ToLocalChecked(); |
597 } | 597 } |
598 | 598 |
599 v8::Local<v8::Value> FXJS_GetObjectElement( | 599 v8::Local<v8::Value> FXJS_GetObjectProperty( |
600 v8::Isolate* pIsolate, | 600 v8::Isolate* pIsolate, |
601 v8::Local<v8::Object> pObj, | 601 v8::Local<v8::Object> pObj, |
602 const CFX_WideString& wsPropertyName) { | 602 const CFX_WideString& wsPropertyName) { |
603 if (pObj.IsEmpty()) | 603 if (pObj.IsEmpty()) |
604 return v8::Local<v8::Value>(); | 604 return v8::Local<v8::Value>(); |
605 v8::Local<v8::Value> val; | 605 v8::Local<v8::Value> val; |
606 if (!pObj->Get(pIsolate->GetCurrentContext(), | 606 if (!pObj->Get(pIsolate->GetCurrentContext(), |
607 FXJS_WSToJSString(pIsolate, wsPropertyName)) | 607 FXJS_WSToJSString(pIsolate, wsPropertyName)) |
608 .ToLocal(&val)) | 608 .ToLocal(&val)) |
609 return v8::Local<v8::Value>(); | 609 return v8::Local<v8::Value>(); |
610 return val; | 610 return val; |
611 } | 611 } |
612 | 612 |
613 v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate, | 613 std::vector<CFX_WideString> FXJS_GetObjectPropertyNames( |
614 v8::Local<v8::Object> pObj) { | 614 v8::Isolate* pIsolate, |
| 615 v8::Local<v8::Object> pObj) { |
615 if (pObj.IsEmpty()) | 616 if (pObj.IsEmpty()) |
616 return v8::Local<v8::Array>(); | 617 return std::vector<CFX_WideString>(); |
| 618 |
617 v8::Local<v8::Array> val; | 619 v8::Local<v8::Array> val; |
618 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) | 620 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) |
619 return v8::Local<v8::Array>(); | 621 return std::vector<CFX_WideString>(); |
620 return val; | 622 |
| 623 std::vector<CFX_WideString> result; |
| 624 for (uint32_t i = 0; i < val->Length(); ++i) { |
| 625 result.push_back(FXJS_ToString( |
| 626 pIsolate, val->Get(pIsolate->GetCurrentContext(), i).ToLocalChecked())); |
| 627 } |
| 628 |
| 629 return result; |
621 } | 630 } |
622 | 631 |
623 void FXJS_PutObjectString(v8::Isolate* pIsolate, | 632 void FXJS_PutObjectString(v8::Isolate* pIsolate, |
624 v8::Local<v8::Object> pObj, | 633 v8::Local<v8::Object> pObj, |
625 const CFX_WideString& wsPropertyName, | 634 const CFX_WideString& wsPropertyName, |
626 const CFX_WideString& wsValue) { | 635 const CFX_WideString& wsValue) { |
627 if (pObj.IsEmpty()) | 636 if (pObj.IsEmpty()) |
628 return; | 637 return; |
629 pObj->Set(pIsolate->GetCurrentContext(), | 638 pObj->Set(pIsolate->GetCurrentContext(), |
630 FXJS_WSToJSString(pIsolate, wsPropertyName), | 639 FXJS_WSToJSString(pIsolate, wsPropertyName), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length())); | 811 return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length())); |
803 } | 812 } |
804 | 813 |
805 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, | 814 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, |
806 v8::Local<v8::Value> pValue) { | 815 v8::Local<v8::Value> pValue) { |
807 if (pValue.IsEmpty()) | 816 if (pValue.IsEmpty()) |
808 return v8::Local<v8::Array>(); | 817 return v8::Local<v8::Array>(); |
809 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 818 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
810 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 819 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
811 } | 820 } |
OLD | NEW |