summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/jsapi
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/jsapi')
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp310
1 files changed, 164 insertions, 146 deletions
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 93c7042729..c03c84b7a7 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -46,8 +46,8 @@ public:
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- v8::Handle<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New(isolate);
- objTemplate->SetInternalFieldCount(1);
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New(isolate);
+ objTemplate->SetInternalFieldCount(2);
m_objTemplate.Reset(isolate, objTemplate);
//Document as the global object.
@@ -70,8 +70,8 @@ public:
unsigned m_bApplyNew;
FX_BOOL m_bSetAsGlobalObject;
- v8::Persistent<v8::ObjectTemplate> m_objTemplate;
- v8::Persistent<v8::Object> m_StaticObj;
+ v8::Global<v8::ObjectTemplate> m_objTemplate;
+ v8::Global<v8::Object> m_StaticObj;
};
int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApplyNew)
@@ -105,7 +105,7 @@ int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate);
- objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)), v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly);
+ objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly);
pObjDef->m_objTemplate.Reset(isolate,objTemp);
return 0;
}
@@ -125,7 +125,7 @@ int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate);
- objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsPropertyName)), pPropGet, pPropPut);
+ objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsPropertyName), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut);
pObjDef->m_objTemplate.Reset(isolate,objTemp);
return 0;
}
@@ -147,7 +147,7 @@ int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::Named
return 0;
}
-int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault)
+int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
@@ -167,7 +167,7 @@ int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
return 0;
}
-static v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime)
+static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
@@ -181,7 +181,7 @@ static v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime*
if(pObjDef->m_bSetAsGlobalObject)
return pObjDef->m_objTemplate;
}
- static v8::Persistent<v8::ObjectTemplate> gloabalObjectTemplate;
+ static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate;
return gloabalObjectTemplate;
}
@@ -197,19 +197,19 @@ int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v
v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(isolate, pMethodCall);
v8::Local<v8::ObjectTemplate> objTemp;
- v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
+ v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
if(globalObjTemp.IsEmpty())
objTemp = v8::ObjectTemplate::New(isolate);
else
objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp);
- objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)), funTempl, v8::ReadOnly);
+ objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v8::NewStringType::kNormal).ToLocalChecked(), funTempl, v8::ReadOnly);
globalObjTemp.Reset(isolate,objTemp);
return 0;
}
-int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault)
+int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Local<v8::Value> pDefault)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
@@ -220,12 +220,12 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
v8::Local<v8::ObjectTemplate> objTemp;
- v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
+ v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
if(globalObjTemp.IsEmpty())
objTemp = v8::ObjectTemplate::New(isolate);
else
objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp);
- objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst)), pDefault, v8::ReadOnly);
+ objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst), v8::NewStringType::kNormal).ToLocalChecked(), pDefault, v8::ReadOnly);
globalObjTemp.Reset(isolate,objTemp);
@@ -233,18 +233,18 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
}
-void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Persistent<v8::Context>& v8PersistentContext)
+void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
- v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
- v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp));
+ v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
+ v8::Local<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp));
v8::Context::Scope context_scope(v8Context);
- //v8::Handle<External> ptr = External::New(isolate, pFXRuntime);
+ //v8::Local<External> ptr = External::New(isolate, pFXRuntime);
//v8Context->SetEmbedderData(1, ptr);
isolate->SetData(2, pFXRuntime);
@@ -256,7 +256,7 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
CFX_WideString ws = CFX_WideString(pObjDef->objName);
CFX_ByteString bs = ws.UTF8Encode();
- v8::Handle<v8::String> objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::String::kNormalString, bs.GetLength());
+ v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked();
if(pObjDef->objType == JS_DYNAMIC)
@@ -268,25 +268,24 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData;
pPrivateData->ObjDefID = i;
- v8::Handle<v8::External> ptr = v8::External::New(isolate, pPrivateData);
- v8Context->Global()->GetPrototype()->ToObject()->SetInternalField(0, ptr);
+ v8Context->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked()->SetAlignedPointerInInternalField(0, pPrivateData);
if(pObjDef->m_pConstructor)
- pObjDef->m_pConstructor(context, v8Context->Global()->GetPrototype()->ToObject(), v8Context->Global()->GetPrototype()->ToObject());
+ pObjDef->m_pConstructor(context, v8Context->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked(), v8Context->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked());
}
}
else
{
- v8::Handle<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntime, context, i);
- v8Context->Global()->Set(objName, obj);
+ v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntime, context, i);
+ v8Context->Global()->Set(v8Context, objName, obj).FromJust();
pObjDef->m_StaticObj.Reset(isolate, obj);
}
}
v8PersistentContext.Reset(isolate, v8Context);
}
-void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8PersistentContext)
+void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
@@ -324,14 +323,15 @@ int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- v8::TryCatch try_catch;
+ v8::TryCatch try_catch(isolate);
CFX_WideString wsScript(script);
CFX_ByteString bsScript = wsScript.UTF8Encode();
- v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLength()));
- if (compiled_script.IsEmpty()) {
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ v8::Local<v8::Script> compiled_script;
+ if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked()).ToLocal(&compiled_script)) {
v8::String::Utf8Value error(try_catch.Exception());
return -1;
}
@@ -342,67 +342,68 @@ int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- v8::TryCatch try_catch;
+ v8::TryCatch try_catch(isolate);
CFX_WideString wsScript(script);
CFX_ByteString bsScript = wsScript.UTF8Encode();
- v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLength()));
- if (compiled_script.IsEmpty()) {
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ v8::Local<v8::Script> compiled_script;
+ if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked()).ToLocal(&compiled_script)) {
v8::String::Utf8Value error(try_catch.Exception());
return -1;
}
- v8::Handle<v8::Value> result = compiled_script->Run();
- if (result.IsEmpty()) {
+ v8::Local<v8::Value> result;
+ if (!compiled_script->Run(context).ToLocal(&result)) {
v8::String::Utf8Value error(try_catch.Exception());
return -1;
}
return 0;
}
-v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID)
+v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
if(-1 == nObjDefnID)
{
v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(isolate);
- return objTempl->NewInstance();
+ v8::Local<v8::Object> obj;
+ if (objTempl->NewInstance(context).ToLocal(&obj)) return obj;
+ return v8::Local<v8::Object>();
}
CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
- if(!pArray) return v8::Handle<v8::Object>();
+ if(!pArray) return v8::Local<v8::Object>();
- if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8::Object>();
+ if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::Object>();
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
- v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate);
-
- v8::Local<v8::Object> obj = objTemp->NewInstance();
-
+ v8::Local<v8::Object> obj;
+ if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::Object>();
CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData;
pPrivateData->ObjDefID = nObjDefnID;
- v8::Handle<v8::External> ptr = v8::External::New(isolate, pPrivateData);
- obj->SetInternalField(0, ptr);
+ obj->SetAlignedPointerInInternalField(0, pPrivateData);
if(pObjDef->m_pConstructor)
- pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetPrototype()->ToObject());
+ pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetPrototype()->ToObject(context).ToLocalChecked());
return obj;
}
-v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
+v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
- if(!pArray) return v8::Handle<v8::Object>();
+ if(!pArray) return v8::Local<v8::Object>();
- if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8::Object>();
+ if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::Object>();
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef->m_StaticObj);
return obj;
@@ -412,30 +413,29 @@ void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID)
{
//Do nothing.
}
-v8::Handle<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
+v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
{
//Return the global object.
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
- if(!pArray) return v8::Handle<v8::Object>();
+ if(!pArray) return v8::Local<v8::Object>();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
- return context->Global()->GetPrototype()->ToObject();
+ return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
}
-int JS_GetObjDefnID(v8::Handle<v8::Object> pObj)
+int JS_GetObjDefnID(v8::Local<v8::Object> pObj)
{
if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1;
- v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(pObj->GetInternalField(0));
- CJS_PrivateData* pPrivateData = (CJS_PrivateData*)field->Value();
+ CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
if(pPrivateData)
return pPrivateData->ObjDefID;
return -1;
}
-IJS_Runtime* JS_GetRuntime(v8::Handle<v8::Object> pObj)
+IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj)
{
if(pObj.IsEmpty()) return NULL;
v8::Local<v8::Context> context = pObj->CreationContext();
@@ -467,7 +467,8 @@ void JS_Error(v8::Isolate* isolate, const CFX_WideString& message)
// intermediate format.
CFX_ByteString utf8_message = message.UTF8Encode();
isolate->ThrowException(v8::String::NewFromUtf8(isolate,
- utf8_message.c_str()));
+ utf8_message.c_str(),
+ v8::NewStringType::kNormal).ToLocalChecked());
}
unsigned JS_CalcHash(const wchar_t* main, unsigned nLen)
@@ -479,7 +480,7 @@ unsigned JS_CalcHash(const wchar_t* main)
{
return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, FXSYS_wcslen(main));
}
-const wchar_t* JS_GetTypeof(v8::Handle<v8::Value> pObj)
+const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj)
{
if(pObj.IsEmpty()) return NULL;
if(pObj->IsString())
@@ -499,254 +500,271 @@ const wchar_t* JS_GetTypeof(v8::Handle<v8::Value> pObj)
return NULL;
}
-void JS_SetPrivate(v8::Handle<v8::Object> pObj, void* p)
+void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p)
{
JS_SetPrivate(NULL, pObj, p);
}
-void* JS_GetPrivate(v8::Handle<v8::Object> pObj)
+void* JS_GetPrivate(v8::Local<v8::Object> pObj)
{
return JS_GetPrivate(NULL,pObj);
}
-void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj, void* p)
+void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj, void* p)
{
if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return;
- v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(pObj->GetInternalField(0));
- CJS_PrivateData* pPrivateData = (CJS_PrivateData*)ptr->Value();
+ CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
if(!pPrivateData) return;
pPrivateData->pPrivate = p;
}
-void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj)
+void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj)
{
if(pObj.IsEmpty()) return NULL;
- v8::Local<v8::Value> value;
+ CJS_PrivateData* pPrivateData = NULL;
if(pObj->InternalFieldCount())
- value = pObj->GetInternalField(0);
+ pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
else
{
//It could be a global proxy object.
v8::Local<v8::Value> v = pObj->GetPrototype();
+ v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
if(v->IsObject())
- value = v->ToObject()->GetInternalField(0);
+ pPrivateData = (CJS_PrivateData*)v->ToObject(context).ToLocalChecked()->GetAlignedPointerFromInternalField(0);
}
- if(value.IsEmpty() || value->IsUndefined()) return NULL;
- v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(value);
- CJS_PrivateData* pPrivateData = (CJS_PrivateData*)ptr->Value();
if(!pPrivateData) return NULL;
return pPrivateData->pPrivate;
}
-void JS_FreePrivate(v8::Handle<v8::Object> pObj)
+void JS_FreePrivate(void* pPrivateData)
{
- if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return;
- v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(pObj->GetInternalField(0));
- delete (CJS_PrivateData*)ptr->Value();
- v8::Local<v8::Context> context = pObj->CreationContext();
+ delete (CJS_PrivateData*)pPrivateData;
+}
- pObj->SetInternalField(0, v8::External::New(context->GetIsolate(), NULL));
+void JS_FreePrivate(v8::Local<v8::Object> pObj)
+{
+ if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return;
+ JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0));
+ pObj->SetAlignedPointerInInternalField(0, NULL);
}
-v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj)
+v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj)
{
return pObj;
}
-v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* PropertyName, int Len = -1)
+v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* PropertyName, int Len = -1)
{
CFX_WideString ws = CFX_WideString(PropertyName,Len);
CFX_ByteString bs = ws.UTF8Encode();
if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent();
- return v8::String::NewFromUtf8(pJSRuntime, bs.c_str());
+ return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), v8::NewStringType::kNormal).ToLocalChecked();
}
-v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj,const wchar_t* PropertyName)
+v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj,const wchar_t* PropertyName)
{
- if(pObj.IsEmpty()) return v8::Handle<v8::Value>();
- return pObj->Get(WSToJSString(pJSRuntime,PropertyName));
+ if(pObj.IsEmpty()) return v8::Local<v8::Value>();
+ v8::Local<v8::Value> val;
+ if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName)).ToLocal(&val)) return v8::Local<v8::Value>();
+ return val;
}
-v8::Handle<v8::Array> JS_GetObjectElementNames(v8::Handle<v8::Object> pObj)
+v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj)
{
- if(pObj.IsEmpty()) return v8::Handle<v8::Array>();
- return pObj->GetPropertyNames();
+ if(pObj.IsEmpty()) return v8::Local<v8::Array>();
+ v8::Local<v8::Array> val;
+ if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&val)) return v8::Local<v8::Array>();
+ return val;
}
-void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue) //VT_string
+void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue) //VT_string
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime, PropertyName), WSToJSString(pJSRuntime, sValue));
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime, PropertyName), WSToJSString(pJSRuntime, sValue)).FromJust();
}
-void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, int nValue)
+void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int nValue)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Int32::New(pJSRuntime, nValue));
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Int32::New(pJSRuntime, nValue)).FromJust();
}
-void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, float fValue)
+void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, float fValue)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRuntime, (double)fValue));
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRuntime, (double)fValue)).FromJust();
}
-void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, double dValue)
+void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, double dValue)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRuntime, (double)dValue));
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRuntime, (double)dValue)).FromJust();
}
-void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, bool bValue)
+void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, bool bValue)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Boolean::New(pJSRuntime, bValue));
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Boolean::New(pJSRuntime, bValue)).FromJust();
}
-void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, v8::Handle<v8::Object> pPut)
+void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::Local<v8::Object> pPut)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),pPut);
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),pPut).FromJust();
}
-void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName)
+void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName)
{
if(pObj.IsEmpty()) return;
- pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Handle<v8::Object>());
+ pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Local<v8::Object>()).FromJust();
}
-v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime)
+v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime)
{
return v8::Array::New(pJSRuntime);
}
-unsigned JS_PutArrayElement(v8::Handle<v8::Array> pArray,unsigned index,v8::Handle<v8::Value> pValue,FXJSVALUETYPE eType)
+unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index,v8::Local<v8::Value> pValue,FXJSVALUETYPE eType)
{
if(pArray.IsEmpty()) return 0;
- pArray->Set(index, pValue);
+ if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothing()) return 0;
return 1;
}
-v8::Handle<v8::Value> JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned index)
+v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index)
{
- if(pArray.IsEmpty()) return v8::Handle<v8::Value>();
- return pArray->Get(index);
+ if(pArray.IsEmpty()) return v8::Local<v8::Value>();
+ v8::Local<v8::Value> val;
+ if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) return v8::Local<v8::Value>();
+ return val;
}
-unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray)
+unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray)
{
if(pArray.IsEmpty()) return 0;
return pArray->Length();
}
-v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number)
+v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number)
{
return v8::Int32::New(pJSRuntime, number);
}
-v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number)
+v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number)
{
return v8::Number::New(pJSRuntime, number);
}
-v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number)
+v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number)
{
return v8::Number::New(pJSRuntime, (float)number);
}
-v8::Handle<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b)
+v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b)
{
return v8::Boolean::New(pJSRuntime, b);
}
-v8::Handle<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj)
+v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj)
{
- if(pObj.IsEmpty()) return v8::Handle<v8::Value>();
+ if(pObj.IsEmpty()) return v8::Local<v8::Value>();
return pObj->Clone();
}
-v8::Handle<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Handle<v8::Array> pObj)
+v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Local<v8::Array> pObj)
{
- if(pObj.IsEmpty()) return v8::Handle<v8::Value>();
+ if(pObj.IsEmpty()) return v8::Local<v8::Value>();
return pObj->Clone();
}
-v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string)
+v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string)
{
return WSToJSString(pJSRuntime, string);
}
-v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen)
+v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen)
{
return WSToJSString(pJSRuntime, string, nLen);
}
-v8::Handle<v8::Value> JS_NewNull()
+v8::Local<v8::Value> JS_NewNull()
{
- return v8::Handle<v8::Value>();
+ return v8::Local<v8::Value>();
}
-v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d)
+v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d)
{
- return v8::Date::New(pJSRuntime, d);
+ return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked();
}
-v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime)
+v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime)
{
- return v8::Handle<v8::Value>();
+ return v8::Local<v8::Value>();
}
-v8::Handle<v8::Value> JS_GetListValue(v8::Handle<v8::Value> pList, int index)
+v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pList, int index)
{
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
if(!pList.IsEmpty() && pList->IsObject())
{
- v8::Local<v8::Object> obj = pList->ToObject();
- return obj->Get(index);
+ v8::Local<v8::Object> obj;
+ if (pList->ToObject(context).ToLocal(&obj))
+ {
+ v8::Local<v8::Value> val;
+ if (obj->Get(context, index).ToLocal(&val)) return val;
+ }
}
- return v8::Handle<v8::Value>();
+ return v8::Local<v8::Value>();
}
-int JS_ToInt32(v8::Handle<v8::Value> pValue)
+int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
if(pValue.IsEmpty()) return 0;
- return pValue->ToInt32()->Value();
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ return pValue->ToInt32(context).ToLocalChecked()->Value();
}
-bool JS_ToBoolean(v8::Handle<v8::Value> pValue)
+bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
if(pValue.IsEmpty()) return false;
- return pValue->ToBoolean()->Value();
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ return pValue->ToBoolean(context).ToLocalChecked()->Value();
}
-double JS_ToNumber(v8::Handle<v8::Value> pValue)
+double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
if(pValue.IsEmpty()) return 0.0;
- return pValue->ToNumber()->Value();
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ return pValue->ToNumber(context).ToLocalChecked()->Value();
}
-v8::Handle<v8::Object> JS_ToObject(v8::Handle<v8::Value> pValue)
+v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
- if(pValue.IsEmpty()) return v8::Handle<v8::Object>();
- return pValue->ToObject();
+ if(pValue.IsEmpty()) return v8::Local<v8::Object>();
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ return pValue->ToObject(context).ToLocalChecked();
}
-CFX_WideString JS_ToString(v8::Handle<v8::Value> pValue)
+CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
if(pValue.IsEmpty()) return L"";
- v8::String::Utf8Value s(pValue->ToString());
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
return CFX_WideString::FromUTF8(*s, s.length());
}
-v8::Handle<v8::Array> JS_ToArray(v8::Handle<v8::Value> pValue)
+v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue)
{
- if(pValue.IsEmpty()) return v8::Handle<v8::Array>();
- return v8::Handle<v8::Array>::Cast(pValue->ToObject());
+ if(pValue.IsEmpty()) return v8::Local<v8::Array>();
+ v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext();
+ return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
}
-void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom)
+void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom)
{
pTo = pFrom;
}
@@ -977,22 +995,22 @@ double JS_DateParse(const wchar_t* string)
v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
//Use the built-in object method.
- v8::Local<v8::Value> v = context->Global()->Get(v8::String::NewFromUtf8(pIsolate, "Date"));
+ v8::Local<v8::Value> v = context->Global()->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
if(v->IsObject())
{
- v8::Local<v8::Object> o = v->ToObject();
- v = o->Get(v8::String::NewFromUtf8(pIsolate, "parse"));
+ v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked();
+ v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
if(v->IsFunction())
{
- v8::Local<v8::Function> funC = v8::Handle<v8::Function>::Cast(v);
+ v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
const int argc = 1;
v8::Local<v8::String> timeStr = WSToJSString(pIsolate, string);
- v8::Handle<v8::Value> argv[argc] = {timeStr};
- v = funC->Call(context->Global(), argc, argv);
+ v8::Local<v8::Value> argv[argc] = {timeStr};
+ v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked();
if(v->IsNumber())
{
- double date = v->ToNumber()->Value();
+ double date = v->ToNumber(context).ToLocalChecked()->Value();
if(!_isfinite(date)) return date;
return date + _getLocalTZA() + _getDaylightSavingTA(date);
}