summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cfxjse_context.cpp94
-rw-r--r--fxjs/cfxjse_context.h6
-rw-r--r--fxjs/cfxjse_value.cpp73
-rw-r--r--fxjs/cfxjse_value.h4
4 files changed, 46 insertions, 131 deletions
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index ad37ca2c0a..bf9bee8652 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -43,6 +43,48 @@ const char szCompatibleModeScript[] =
wchar_t g_FXJSETagString[] = L"FXJSE_HostObject";
+v8::Local<v8::Object> CreateReturnValue(v8::Isolate* pIsolate,
+ v8::TryCatch& trycatch) {
+ v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
+ if (trycatch.HasCaught()) {
+ v8::Local<v8::Value> hException = trycatch.Exception();
+ v8::Local<v8::Message> hMessage = trycatch.Message();
+ if (hException->IsObject()) {
+ v8::Local<v8::Value> hValue;
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "name"));
+ if (hValue->IsString() || hValue->IsStringObject())
+ hReturnValue->Set(0, hValue);
+ else
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "message"));
+ if (hValue->IsString() || hValue->IsStringObject())
+ hReturnValue->Set(1, hValue);
+ else
+ hReturnValue->Set(1, hMessage->Get());
+ } else {
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+ hReturnValue->Set(1, hMessage->Get());
+ }
+ hReturnValue->Set(2, hException);
+ hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
+ hReturnValue->Set(4, hMessage->GetSourceLine());
+ v8::Maybe<int32_t> maybe_int =
+ hMessage->GetStartColumn(pIsolate->GetCurrentContext());
+ hReturnValue->Set(5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
+ maybe_int = hMessage->GetEndColumn(pIsolate->GetCurrentContext());
+ hReturnValue->Set(6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
+ }
+ return hReturnValue;
+}
+
+v8::Local<v8::Object> GetGlobalObjectFromContext(
+ v8::Local<v8::Context> hContext) {
+ return hContext->Global()->GetPrototype().As<v8::Object>();
+}
+
} // namespace
// Note, not in the anonymous namespace due to the friend call
@@ -73,11 +115,6 @@ class CFXJSE_ScopeUtil_IsolateHandleContext {
v8::Context::Scope m_cscope;
};
-v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
- v8::Local<v8::Context> hContext) {
- return hContext->Global()->GetPrototype().As<v8::Object>();
-}
-
void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject,
CFXJSE_HostObject* lpNewBinding) {
ASSERT(!hObject.IsEmpty());
@@ -115,43 +152,6 @@ CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(v8::Local<v8::Object> hJSObject,
hObject->GetAlignedPointerFromInternalField(1));
}
-v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
- v8::TryCatch& trycatch) {
- v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
- if (trycatch.HasCaught()) {
- v8::Local<v8::Value> hException = trycatch.Exception();
- v8::Local<v8::Message> hMessage = trycatch.Message();
- if (hException->IsObject()) {
- v8::Local<v8::Value> hValue;
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "name"));
- if (hValue->IsString() || hValue->IsStringObject())
- hReturnValue->Set(0, hValue);
- else
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
-
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "message"));
- if (hValue->IsString() || hValue->IsStringObject())
- hReturnValue->Set(1, hValue);
- else
- hReturnValue->Set(1, hMessage->Get());
- } else {
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
- hReturnValue->Set(1, hMessage->Get());
- }
- hReturnValue->Set(2, hException);
- hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
- hReturnValue->Set(4, hMessage->GetSourceLine());
- v8::Maybe<int32_t> maybe_int =
- hMessage->GetStartColumn(pIsolate->GetCurrentContext());
- hReturnValue->Set(5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
- maybe_int = hMessage->GetEndColumn(pIsolate->GetCurrentContext());
- hReturnValue->Set(6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
- }
- return hReturnValue;
-}
-
// static
std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Isolate* pIsolate,
@@ -182,8 +182,7 @@ std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Local<v8::Context> hRootContext = v8::Local<v8::Context>::New(
pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(hNewContext);
+ v8::Local<v8::Object> hGlobalObject = GetGlobalObjectFromContext(hNewContext);
FXJSE_UpdateObjectBinding(hGlobalObject, pGlobalObject);
pContext->m_hContext.Reset(pIsolate, hNewContext);
return pContext;
@@ -198,8 +197,7 @@ std::unique_ptr<CFXJSE_Value> CFXJSE_Context::GetGlobalObject() {
CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
v8::Local<v8::Context> hContext =
v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(hContext);
+ v8::Local<v8::Object> hGlobalObject = GetGlobalObjectFromContext(hContext);
pValue->ForceSetValue(hGlobalObject);
return pValue;
}
@@ -245,7 +243,7 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript,
}
if (lpRetValue) {
lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ CreateReturnValue(m_pIsolate, trycatch));
}
return false;
}
@@ -270,7 +268,7 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript,
}
if (lpRetValue) {
lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ CreateReturnValue(m_pIsolate, trycatch));
}
return false;
}
diff --git a/fxjs/cfxjse_context.h b/fxjs/cfxjse_context.h
index f93469bc4d..48816eb629 100644
--- a/fxjs/cfxjse_context.h
+++ b/fxjs/cfxjse_context.h
@@ -49,12 +49,6 @@ class CFXJSE_Context {
std::vector<std::unique_ptr<CFXJSE_Class>> m_rgClasses;
};
-v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
- v8::TryCatch& trycatch);
-
-v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
- v8::Local<v8::Context> hContext);
-
void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject,
CFXJSE_HostObject* lpNewBinding = nullptr);
diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp
index 0a135951d9..f5bdd54653 100644
--- a/fxjs/cfxjse_value.cpp
+++ b/fxjs/cfxjse_value.cpp
@@ -261,79 +261,6 @@ bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction,
return true;
}
-#define FXJSE_INVALID_PTR ((void*)(intptr_t)-1)
-bool CFXJSE_Value::Call(CFXJSE_Value* lpReceiver,
- CFXJSE_Value* lpRetValue,
- uint32_t nArgCount,
- CFXJSE_Value** lpArgs) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hFunctionValue =
- v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue());
- v8::Local<v8::Object> hFunctionObject =
- !hFunctionValue.IsEmpty() && hFunctionValue->IsObject()
- ? hFunctionValue.As<v8::Object>()
- : v8::Local<v8::Object>();
-
- v8::TryCatch trycatch(m_pIsolate);
- if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) {
- if (lpRetValue)
- lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch));
- return false;
- }
-
- v8::Local<v8::Value> hReturnValue;
- v8::Local<v8::Value>* lpLocalArgs = NULL;
- if (nArgCount) {
- lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount);
- for (uint32_t i = 0; i < nArgCount; i++) {
- new (lpLocalArgs + i) v8::Local<v8::Value>;
- CFXJSE_Value* lpArg = lpArgs[i];
- if (lpArg) {
- lpLocalArgs[i] =
- v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue());
- }
- if (lpLocalArgs[i].IsEmpty()) {
- lpLocalArgs[i] = v8::Undefined(m_pIsolate);
- }
- }
- }
-
- bool bRetValue = true;
- if (lpReceiver == FXJSE_INVALID_PTR) {
- v8::MaybeLocal<v8::Value> maybe_retvalue =
- hFunctionObject->CallAsConstructor(m_pIsolate->GetCurrentContext(),
- nArgCount, lpLocalArgs);
- hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>());
- } else {
- v8::Local<v8::Value> hReceiver;
- if (lpReceiver) {
- hReceiver =
- v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue());
- }
- if (hReceiver.IsEmpty() || !hReceiver->IsObject())
- hReceiver = v8::Object::New(m_pIsolate);
-
- v8::MaybeLocal<v8::Value> maybe_retvalue = hFunctionObject->CallAsFunction(
- m_pIsolate->GetCurrentContext(), hReceiver, nArgCount, lpLocalArgs);
- hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>());
- }
-
- if (trycatch.HasCaught()) {
- hReturnValue = FXJSE_CreateReturnValue(m_pIsolate, trycatch);
- bRetValue = false;
- }
-
- if (lpRetValue)
- lpRetValue->ForceSetValue(hReturnValue);
-
- if (lpLocalArgs) {
- for (uint32_t i = 0; i < nArgCount; i++)
- lpLocalArgs[i].~Local();
- FX_Free(lpLocalArgs);
- }
- return bRetValue;
-}
-
bool CFXJSE_Value::IsUndefined() const {
if (m_hValue.IsEmpty())
return false;
diff --git a/fxjs/cfxjse_value.h b/fxjs/cfxjse_value.h
index 52905db90f..52bb036b95 100644
--- a/fxjs/cfxjse_value.h
+++ b/fxjs/cfxjse_value.h
@@ -68,10 +68,6 @@ class CFXJSE_Value {
bool SetObjectOwnProperty(const ByteStringView& szPropName,
CFXJSE_Value* lpPropValue);
bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
- bool Call(CFXJSE_Value* lpReceiver,
- CFXJSE_Value* lpRetValue,
- uint32_t nArgCount,
- CFXJSE_Value** lpArgs);
v8::Isolate* GetIsolate() const { return m_pIsolate; }
const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; }