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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fxjs/fxjs_v8.h ('k') | fxjs/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fxjs/fxjs_v8.cpp
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 5ce8c475698b2e831223d84f76e170cc8bec7ee6..c96cc1f0e0c25fab7ab6092cf47f2b9f8c258395 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());
« 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