summaryrefslogtreecommitdiff
path: root/fxjs/fxjs_v8.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs/fxjs_v8.cpp')
-rw-r--r--fxjs/fxjs_v8.cpp90
1 files changed, 16 insertions, 74 deletions
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 5ce8c47569..c96cc1f0e0 100644
--- a/fxjs/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -596,79 +596,21 @@ std::vector<CFX_WideString> CFXJS_Engine::GetObjectPropertyNames(
std::vector<CFX_WideString> result;
for (uint32_t i = 0; i < val->Length(); ++i) {
- result.push_back(ToString(val->Get(context, i).ToLocalChecked()));
+ result.push_back(ToWideString(val->Get(context, i).ToLocalChecked()));
}
return result;
}
-void CFXJS_Engine::PutObjectString(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- const CFX_WideString& wsValue) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- WSToJSString(wsValue))
- .FromJust();
-}
-
-void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- int nValue) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- v8::Int32::New(m_isolate, nValue))
- .FromJust();
-}
-
-void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- float fValue) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- v8::Number::New(m_isolate, (double)fValue))
- .FromJust();
-}
-
-void CFXJS_Engine::PutObjectNumber(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- double dValue) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- v8::Number::New(m_isolate, (double)dValue))
- .FromJust();
-}
-
-void CFXJS_Engine::PutObjectBoolean(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- bool bValue) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- v8::Boolean::New(m_isolate, bValue))
- .FromJust();
-}
-
-void CFXJS_Engine::PutObjectObject(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName,
- v8::Local<v8::Object> pPut) {
+void CFXJS_Engine::PutObjectProperty(v8::Local<v8::Object> pObj,
+ const CFX_WideString& wsPropertyName,
+ v8::Local<v8::Value> pPut) {
if (pObj.IsEmpty())
return;
pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName), pPut)
.FromJust();
}
-void CFXJS_Engine::PutObjectNull(v8::Local<v8::Object> pObj,
- const CFX_WideString& wsPropertyName) {
- if (pObj.IsEmpty())
- return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName),
- v8::Local<v8::Object>())
- .FromJust();
-}
v8::Local<v8::Array> CFXJS_Engine::NewArray() {
return v8::Array::New(m_isolate);
@@ -724,8 +666,8 @@ v8::Local<v8::Value> CFXJS_Engine::NewBoolean(bool b) {
return v8::Boolean::New(m_isolate, b);
}
-v8::Local<v8::Value> CFXJS_Engine::NewString(const wchar_t* str) {
- return WSToJSString(str);
+v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_WideString& str) {
+ return WSToJSString(str.c_str());
}
v8::Local<v8::Value> CFXJS_Engine::NewNull() {
@@ -752,30 +694,30 @@ bool CFXJS_Engine::ToBoolean(v8::Local<v8::Value> pValue) {
return pValue->ToBoolean(context).ToLocalChecked()->Value();
}
-double CFXJS_Engine::ToNumber(v8::Local<v8::Value> pValue) {
+double CFXJS_Engine::ToDouble(v8::Local<v8::Value> pValue) {
if (pValue.IsEmpty())
return 0.0;
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
return pValue->ToNumber(context).ToLocalChecked()->Value();
}
-v8::Local<v8::Object> CFXJS_Engine::ToObject(v8::Local<v8::Value> pValue) {
+CFX_WideString CFXJS_Engine::ToWideString(v8::Local<v8::Value> pValue) {
if (pValue.IsEmpty())
- return v8::Local<v8::Object>();
+ return CFX_WideString();
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
- return pValue->ToObject(context).ToLocalChecked();
+ v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
+ return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length()));
}
-CFX_WideString CFXJS_Engine::ToString(v8::Local<v8::Value> pValue) {
- if (pValue.IsEmpty())
- return L"";
+v8::Local<v8::Object> CFXJS_Engine::ToObject(v8::Local<v8::Value> pValue) {
+ if (pValue.IsEmpty() || !pValue->IsObject())
+ return v8::Local<v8::Object>();
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
- v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
- return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length()));
+ return pValue->ToObject(context).ToLocalChecked();
}
v8::Local<v8::Array> CFXJS_Engine::ToArray(v8::Local<v8::Value> pValue) {
- if (pValue.IsEmpty())
+ if (pValue.IsEmpty() || !pValue->IsArray())
return v8::Local<v8::Array>();
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());