From d94df885e9e680e7dc8a5ac116c8d4ab5e4790cd Mon Sep 17 00:00:00 2001 From: Jochen Eisinger Date: Sun, 17 May 2015 13:07:02 +0200 Subject: Replace deprecated with non-deprecated V8 APIs In most cases, we just CHECK() that no exception was thrown. Previously, we'd just crash. Ideally, this should all be fixed and the system should cope with those exceptions, but that's beyond this CL. R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1126203010 --- fpdfsdk/include/jsapi/fxjs_v8.h | 20 ++--- fpdfsdk/src/javascript/JS_Value.cpp | 39 +++++----- fpdfsdk/src/javascript/global.cpp | 13 ++-- fpdfsdk/src/jsapi/fxjs_v8.cpp | 143 +++++++++++++++++++++--------------- 4 files changed, 120 insertions(+), 95 deletions(-) diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 7f23380406..d84b216117 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -86,7 +86,7 @@ void JS_FreePrivate(void* p); void JS_FreePrivate(v8::Handle pObj); v8::Handle JS_GetObjectValue(v8::Handle pObj); v8::Handle JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle pObj,const wchar_t* PropertyName); -v8::Handle JS_GetObjectElementNames(v8::Handle pObj); +v8::Handle JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Handle pObj); void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName, const wchar_t* sValue); void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName, int nValue); void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName, float fValue); @@ -94,10 +94,10 @@ void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle pOb void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName, bool bValue); void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName, v8::Handle pPut); void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle pObj, const wchar_t* PropertyName); -unsigned JS_PutArrayElement(v8::Handle pArray,unsigned index,v8::Handle pValue,FXJSVALUETYPE eType); -v8::Handle JS_GetArrayElemnet(v8::Handle pArray,unsigned index); +unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Handle pArray,unsigned index,v8::Handle pValue,FXJSVALUETYPE eType); +v8::Handle JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Handle pArray,unsigned index); unsigned JS_GetArrayLength(v8::Handle pArray); -v8::Handle JS_GetListValue(v8::Handle pList, int index); +v8::Handle JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Handle pList, int index); v8::Handle JS_NewArray(IJS_Runtime* pJSRuntime); @@ -114,12 +114,12 @@ v8::Handle JS_NewDate(IJS_Runtime* pJSRuntime,double d); v8::Handle JS_NewValue(IJS_Runtime* pJSRuntime); -int JS_ToInt32(v8::Handle pValue); -bool JS_ToBoolean(v8::Handle pValue); -double JS_ToNumber(v8::Handle pValue); -v8::Handle JS_ToObject(v8::Handle pValue); -CFX_WideString JS_ToString(v8::Handle pValue); -v8::Handle JS_ToArray(v8::Handle pValue); +int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Handle pValue); +bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Handle pValue); +double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Handle pValue); +v8::Handle JS_ToObject(IJS_Runtime* pJSRuntime, v8::Handle pValue); +CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, v8::Handle pValue); +v8::Handle JS_ToArray(IJS_Runtime* pJSRuntime, v8::Handle pValue); void JS_ValueCopy(v8::Handle& pTo, v8::Handle pFrom); double JS_GetDateTime(); diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp index 1b36f314ca..d3de6d1719 100644 --- a/fpdfsdk/src/javascript/JS_Value.cpp +++ b/fpdfsdk/src/javascript/JS_Value.cpp @@ -98,17 +98,17 @@ void CJS_Value::Detach() int CJS_Value::ToInt() const { - return JS_ToInt32(m_pValue); + return JS_ToInt32(m_isolate, m_pValue); } bool CJS_Value::ToBool() const { - return JS_ToBoolean(m_pValue); + return JS_ToBoolean(m_isolate, m_pValue); } double CJS_Value::ToDouble() const { - return JS_ToNumber(m_pValue); + return JS_ToNumber(m_isolate, m_pValue); } float CJS_Value::ToFloat() const @@ -118,18 +118,18 @@ float CJS_Value::ToFloat() const CJS_Object* CJS_Value::ToCJSObject() const { - v8::Handle pObj = JS_ToObject(m_pValue); + v8::Handle pObj = JS_ToObject(m_isolate, m_pValue); return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); } v8::Handle CJS_Value::ToV8Object() const { - return JS_ToObject(m_pValue); + return JS_ToObject(m_isolate, m_pValue); } CFX_WideString CJS_Value::ToCFXWideString() const { - return JS_ToString(m_pValue); + return JS_ToString(m_isolate, m_pValue); } CFX_ByteString CJS_Value::ToCFXByteString() const @@ -145,7 +145,7 @@ v8::Handle CJS_Value::ToV8Value() const v8::HandleCJS_Value::ToV8Array() const { if (IsArrayObject()) - return v8::Handle::Cast(JS_ToObject(m_pValue)); + return v8::Handle::Cast(JS_ToObject(m_isolate, m_pValue)); return v8::Handle(); } @@ -238,6 +238,7 @@ void CJS_Value::operator = (CJS_Value value) m_pValue = value.ToV8Value(); m_eType = value.m_eType; + m_isolate = value.m_isolate; } /* ---------------------------------------------------------------------------------------- */ @@ -272,7 +273,7 @@ FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const { if (IsArrayObject()) { - array.Attach(JS_ToArray(m_pValue)); + array.Attach(JS_ToArray(m_isolate, m_pValue)); return TRUE; } @@ -488,7 +489,7 @@ void CJS_Array::GetElement(unsigned index,CJS_Value &value) { if (m_pArray.IsEmpty()) return; - v8::Handle p = JS_GetArrayElemnet(m_pArray,index); + v8::Handle p = JS_GetArrayElement(m_isolate, m_pArray,index); value.Attach(p,VT_object); } @@ -497,7 +498,7 @@ void CJS_Array::SetElement(unsigned index,CJS_Value value) if (m_pArray.IsEmpty()) m_pArray = JS_NewArray(m_isolate); - JS_PutArrayElement(m_pArray, index, value.ToV8Value(), value.GetType()); + JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.GetType()); } int CJS_Array::GetLength() @@ -545,7 +546,7 @@ CJS_Date::~CJS_Date() FX_BOOL CJS_Date::IsValidDate() { if(m_pDate.IsEmpty()) return FALSE; - return !JS_PortIsNan(JS_ToNumber(m_pDate)); + return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); } void CJS_Date::Attach(v8::Handle pDate) @@ -556,7 +557,7 @@ void CJS_Date::Attach(v8::Handle pDate) int CJS_Date::GetYear() { if (IsValidDate()) - return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -570,7 +571,7 @@ void CJS_Date::SetYear(int iYear) int CJS_Date::GetMonth() { if (IsValidDate()) - return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -586,7 +587,7 @@ void CJS_Date::SetMonth(int iMonth) int CJS_Date::GetDay() { if (IsValidDate()) - return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -602,7 +603,7 @@ void CJS_Date::SetDay(int iDay) int CJS_Date::GetHours() { if (IsValidDate()) - return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -616,7 +617,7 @@ void CJS_Date::SetHours(int iHours) int CJS_Date::GetMinutes() { if (IsValidDate()) - return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -630,7 +631,7 @@ void CJS_Date::SetMinutes(int minutes) int CJS_Date::GetSeconds() { if (IsValidDate()) - return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate))); + return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); return 0; } @@ -650,12 +651,12 @@ CJS_Date::operator double() const { if(m_pDate.IsEmpty()) return 0.0; - return JS_ToNumber(m_pDate); + return JS_ToNumber(m_isolate, m_pDate); } CFX_WideString CJS_Date::ToString() const { if(m_pDate.IsEmpty()) return L""; - return JS_ToString(m_pDate); + return JS_ToString(m_isolate, m_pDate); } diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp index 418508f89e..99db9e7a71 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -387,16 +387,15 @@ void global_alternate::CommitGlobalPersisitentVariables() void global_alternate::ObjectToArray(v8::Handle pObj, CJS_GlobalVariableArray& array) { - v8::Handle pKeyList = JS_GetObjectElementNames(pObj); - int nObjElements = pKeyList->Length(); - v8::Local context = pObj->CreationContext(); v8::Isolate* isolate = context->GetIsolate(); + v8::Handle pKeyList = JS_GetObjectElementNames(isolate, pObj); + int nObjElements = pKeyList->Length(); for (int i=0; i v = JS_GetObjectElement(isolate, pObj, ws.c_str()); @@ -408,7 +407,7 @@ void global_alternate::ObjectToArray(v8::Handle pObj, CJS_GlobalVari CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER; pObjElement->sKey = sKey; - pObjElement->dData = JS_ToNumber(v); + pObjElement->dData = JS_ToNumber(isolate, v); array.Add(pObjElement); } break; @@ -417,7 +416,7 @@ void global_alternate::ObjectToArray(v8::Handle pObj, CJS_GlobalVari CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN; pObjElement->sKey = sKey; - pObjElement->dData = JS_ToBoolean(v); + pObjElement->dData = JS_ToBoolean(isolate, v); array.Add(pObjElement); } break; @@ -436,7 +435,7 @@ void global_alternate::ObjectToArray(v8::Handle pObj, CJS_GlobalVari CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT; pObjElement->sKey = sKey; - ObjectToArray(JS_ToObject(v), pObjElement->objData); + ObjectToArray(JS_ToObject(isolate, v), pObjElement->objData); array.Add(pObjElement); } break; diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 59c99acdfe..b1adeb7112 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -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 objTemp = v8::Local::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 objTemp = v8::Local::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; } @@ -202,7 +202,7 @@ int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v objTemp = v8::ObjectTemplate::New(isolate); else objTemp = v8::Local::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); @@ -225,7 +225,7 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8: objTemp = v8::ObjectTemplate::New(isolate); else objTemp = v8::Local::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); @@ -254,7 +254,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 objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::String::kNormalString, bs.GetLength()); + v8::Handle objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); if(pObjDef->objType == JS_DYNAMIC) @@ -266,16 +266,16 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_ CJS_PrivateData* pPrivateData = new CJS_PrivateData; pPrivateData->ObjDefID = i; - v8Context->Global()->GetPrototype()->ToObject()->SetAlignedPointerInInternalField(0, pPrivateData); + 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 obj = JS_NewFxDynamicObj(pJSRuntime, context, i); - v8Context->Global()->Set(objName, obj); + v8Context->Global()->Set(v8Context, objName, obj).FromJust(); pObjDef->m_StaticObj.Reset(isolate, obj); } } @@ -320,14 +320,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 compiled_script = v8::Script::Compile(v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLength())); - if (compiled_script.IsEmpty()) { + v8::Local context = isolate->GetCurrentContext(); + v8::Local 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; } @@ -338,19 +339,20 @@ 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 compiled_script = v8::Script::Compile(v8::String::NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLength())); - if (compiled_script.IsEmpty()) { + v8::Local context = isolate->GetCurrentContext(); + v8::Local 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 result = compiled_script->Run(); - if (result.IsEmpty()) { + v8::Handle result; + if (!compiled_script->Run(context).ToLocal(&result)) { v8::String::Utf8Value error(try_catch.Exception()); return -1; } @@ -361,10 +363,13 @@ v8::Handle JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context { v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; v8::Isolate::Scope isolate_scope(isolate); + v8::Local context = isolate->GetCurrentContext(); if(-1 == nObjDefnID) { v8::Local objTempl = v8::ObjectTemplate::New(isolate); - return objTempl->NewInstance(); + v8::Local obj; + if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; + return v8::Handle(); } CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); @@ -374,16 +379,16 @@ v8::Handle JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle(); CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); - v8::Local context = isolate->GetCurrentContext(); v8::Local objTemp = v8::Local::New(isolate, pObjDef->m_objTemplate); - v8::Local obj = objTemp->NewInstance(); + v8::Local obj; + if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local(); CJS_PrivateData* pPrivateData = new CJS_PrivateData; pPrivateData->ObjDefID = nObjDefnID; 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; } @@ -416,7 +421,7 @@ v8::Handle JS_GetThisObj(IJS_Runtime * pJSRuntime) if(!pArray) return v8::Handle(); v8::Local context = isolate->GetCurrentContext(); - return context->Global()->GetPrototype()->ToObject(); + return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); } int JS_GetObjDefnID(v8::Handle pObj) @@ -460,7 +465,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) @@ -520,8 +526,10 @@ void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle pObj) { //It could be a global proxy object. v8::Local v = pObj->GetPrototype(); + v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; + v8::Local context = isolate->GetCurrentContext(); if(v->IsObject()) - pPrivateData = (CJS_PrivateData*)v->ToObject()->GetAlignedPointerFromInternalField(0); + pPrivateData = (CJS_PrivateData*)v->ToObject(context).ToLocalChecked()->GetAlignedPointerFromInternalField(0); } if(!pPrivateData) return NULL; return pPrivateData->pPrivate; @@ -550,61 +558,65 @@ v8::Handle WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prop 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 JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle pObj,const wchar_t* PropertyName) { if(pObj.IsEmpty()) return v8::Handle(); - return pObj->Get(WSToJSString(pJSRuntime,PropertyName)); + v8::Local val; + if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName)).ToLocal(&val)) return v8::Handle(); + return val; } -v8::Handle JS_GetObjectElementNames(v8::Handle pObj) +v8::Handle JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Handle pObj) { if(pObj.IsEmpty()) return v8::Handle(); - return pObj->GetPropertyNames(); + v8::Local val; + if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&val)) return v8::Local(); + return val; } void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle 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 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 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 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 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 pObj, const wchar_t* PropertyName, v8::Handle 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 pObj, const wchar_t* PropertyName) { if(pObj.IsEmpty()) return; - pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Handle()); + pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,PropertyName),v8::Handle()).FromJust(); } v8::Handle JS_NewArray(IJS_Runtime* pJSRuntime) @@ -612,17 +624,19 @@ v8::Handle JS_NewArray(IJS_Runtime* pJSRuntime) return v8::Array::New(pJSRuntime); } -unsigned JS_PutArrayElement(v8::Handle pArray,unsigned index,v8::Handle pValue,FXJSVALUETYPE eType) +unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Handle pArray,unsigned index,v8::Handle 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 JS_GetArrayElemnet(v8::Handle pArray,unsigned index) +v8::Handle JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Handle pArray,unsigned index) { if(pArray.IsEmpty()) return v8::Handle(); - return pArray->Get(index); + v8::Local val; + if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) return v8::Local(); + return val; } unsigned JS_GetArrayLength(v8::Handle pArray) @@ -681,7 +695,7 @@ v8::Handle JS_NewNull() v8::Handle JS_NewDate(IJS_Runtime* pJSRuntime,double d) { - return v8::Date::New(pJSRuntime, d); + return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(); } v8::Handle JS_NewValue(IJS_Runtime* pJSRuntime) @@ -689,52 +703,63 @@ v8::Handle JS_NewValue(IJS_Runtime* pJSRuntime) return v8::Handle(); } -v8::Handle JS_GetListValue(v8::Handle pList, int index) +v8::Handle JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Handle pList, int index) { + v8::Local context = pJSRuntime->GetCurrentContext(); if(!pList.IsEmpty() && pList->IsObject()) { - v8::Local obj = pList->ToObject(); - return obj->Get(index); + v8::Local obj; + if (pList->ToObject(context).ToLocal(&obj)) + { + v8::Local val; + if (obj->Get(context, index).ToLocal(&val)) return val; + } } return v8::Handle(); } -int JS_ToInt32(v8::Handle pValue) +int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return 0; - return pValue->ToInt32()->Value(); + v8::Local context = pJSRuntime->GetCurrentContext(); + return pValue->ToInt32(context).ToLocalChecked()->Value(); } -bool JS_ToBoolean(v8::Handle pValue) +bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return false; - return pValue->ToBoolean()->Value(); + v8::Local context = pJSRuntime->GetCurrentContext(); + return pValue->ToBoolean(context).ToLocalChecked()->Value(); } -double JS_ToNumber(v8::Handle pValue) +double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return 0.0; - return pValue->ToNumber()->Value(); + v8::Local context = pJSRuntime->GetCurrentContext(); + return pValue->ToNumber(context).ToLocalChecked()->Value(); } -v8::Handle JS_ToObject(v8::Handle pValue) +v8::Handle JS_ToObject(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return v8::Handle(); - return pValue->ToObject(); + v8::Local context = pJSRuntime->GetCurrentContext(); + return pValue->ToObject(context).ToLocalChecked(); } -CFX_WideString JS_ToString(v8::Handle pValue) +CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return L""; - v8::String::Utf8Value s(pValue->ToString()); + v8::Local context = pJSRuntime->GetCurrentContext(); + v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); return CFX_WideString::FromUTF8(*s, s.length()); } -v8::Handle JS_ToArray(v8::Handle pValue) +v8::Handle JS_ToArray(IJS_Runtime* pJSRuntime, v8::Handle pValue) { if(pValue.IsEmpty()) return v8::Handle(); - return v8::Handle::Cast(pValue->ToObject()); + v8::Local context = pJSRuntime->GetCurrentContext(); + return v8::Handle::Cast(pValue->ToObject(context).ToLocalChecked()); } void JS_ValueCopy(v8::Handle& pTo, v8::Handle pFrom) @@ -968,11 +993,11 @@ double JS_DateParse(const wchar_t* string) v8::Local context = pIsolate->GetCurrentContext(); //Use the built-in object method. - v8::Local v = context->Global()->Get(v8::String::NewFromUtf8(pIsolate, "Date")); + v8::Local v = context->Global()->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); if(v->IsObject()) { - v8::Local o = v->ToObject(); - v = o->Get(v8::String::NewFromUtf8(pIsolate, "parse")); + v8::Local o = v->ToObject(context).ToLocalChecked(); + v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); if(v->IsFunction()) { v8::Local funC = v8::Handle::Cast(v); @@ -980,10 +1005,10 @@ double JS_DateParse(const wchar_t* string) const int argc = 1; v8::Local timeStr = WSToJSString(pIsolate, string); v8::Handle argv[argc] = {timeStr}; - v = funC->Call(context->Global(), argc, argv); + 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); } -- cgit v1.2.3