1ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// Copyright 2014 PDFium Authors. All rights reserved. 2ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// Use of this source code is governed by a BSD-style license that can be 3ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// found in the LICENSE file. 4ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 5ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 7ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "xfa/src/foxitlib.h" 8ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "fxv8.h" 9ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "class.h" 10ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "value.h" 11ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_DynPropGetterAdapter_MethodCallback( 12ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 13ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); 14ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>( 15ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetAlignedPointerFromInternalField(0)); 16ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = 17ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetInternalField(1).As<v8::String>(); 18ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass && !hPropName.IsEmpty()); 19ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 20ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName = *szPropName; 21ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 22ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(info.This()); 23ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); 24ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; 25ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynMethodCall(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), 26ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann szFxPropName, 27ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<CFXJSE_Arguments&>(impl)); 28ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!lpRetValue->DirectGetValue().IsEmpty()) { 29ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(lpRetValue->DirectGetValue()); 30ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 31ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpRetValue; 32ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpRetValue = nullptr; 33ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 34ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 35ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 36ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass, 37ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HOBJECT hObject, 38ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const CFX_ByteStringC& szPropName, 39ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HVALUE hValue) { 40ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass); 41ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann int32_t nPropType = 42ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropTypeGetter == nullptr 43ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_ClassPropType_Property 44ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE); 45ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (nPropType == FXJSE_ClassPropType_Property) { 46ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (lpClass->dynPropGetter) { 47ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropGetter(hObject, szPropName, hValue); 48ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 49ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } else if (nPropType == FXJSE_ClassPropType_Method) { 50ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (lpClass->dynMethodCall && hValue) { 51ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); 52ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = lpValue->GetIsolate(); 53ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope hscope(pIsolate); 54ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate = 55ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::ObjectTemplate::New(); 56ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfoTemplate->SetInternalFieldCount(2); 57ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hCallBackInfo = 58ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfoTemplate->NewInstance(); 59ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->SetAlignedPointerInInternalField( 60ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 0, const_cast<FXJSE_CLASS*>(lpClass)); 61ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->SetInternalField( 62ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 1, v8::String::NewFromUtf8( 63ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann pIsolate, reinterpret_cast<const char*>(szPropName.GetPtr()), 64ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::kNormalString, szPropName.GetLength())); 65ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpValue->ForceSetValue(v8::Function::New( 66ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpValue->GetIsolate(), FXJSE_DynPropGetterAdapter_MethodCallback, 67ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo)); 68ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 69ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 70ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 71ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_DynPropSetterAdapter(const FXJSE_CLASS* lpClass, 72ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HOBJECT hObject, 73ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const CFX_ByteStringC& szPropName, 74ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HVALUE hValue) { 75ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass); 76ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann int32_t nPropType = 77ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropTypeGetter == nullptr 78ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_ClassPropType_Property 79ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE); 80ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (nPropType != FXJSE_ClassPropType_Method) { 81ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (lpClass->dynPropSetter) { 82ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropSetter(hObject, szPropName, hValue); 83ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 84ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 85ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 86ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic FX_BOOL FXJSE_DynPropQueryAdapter(const FXJSE_CLASS* lpClass, 87ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HOBJECT hObject, 88ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const CFX_ByteStringC& szPropName) { 89ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass); 90ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann int32_t nPropType = 91ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropTypeGetter == nullptr 92ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_ClassPropType_Property 93ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : lpClass->dynPropTypeGetter(hObject, szPropName, TRUE); 94ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return nPropType != FXJSE_ClassPropType_None; 95ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 96ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic FX_BOOL FXJSE_DynPropDeleterAdapter(const FXJSE_CLASS* lpClass, 97ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_HOBJECT hObject, 98ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const CFX_ByteStringC& szPropName) { 99ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass); 100ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann int32_t nPropType = 101ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass->dynPropTypeGetter == nullptr 102ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_ClassPropType_Property 103ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE); 104ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (nPropType != FXJSE_ClassPropType_Method) { 105ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (lpClass->dynPropDeleter) { 106ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return lpClass->dynPropDeleter(hObject, szPropName); 107ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } else { 108ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return nPropType == FXJSE_ClassPropType_Property ? FALSE : TRUE; 109ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 110ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 111ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return FALSE; 112ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 113ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter( 114ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 115ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); 116ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>( 117ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetAlignedPointerFromInternalField(0)); 118ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = 119ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetInternalField(1).As<v8::String>(); 120ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass && !hPropName.IsEmpty()); 121ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 122ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName = *szPropName; 123ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 124ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); 125ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(info.This()); 126ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropGetterAdapter( 127ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, 128ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HVALUE>(lpNewValue)); 129ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(lpNewValue->DirectGetValue()); 130ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 131ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 132ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpNewValue; 133ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpNewValue = nullptr; 134ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 135ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter( 136ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 137ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); 138ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>( 139ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetAlignedPointerFromInternalField(0)); 140ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = 141ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->GetInternalField(1).As<v8::String>(); 142ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ASSERT(lpClass && !hPropName.IsEmpty()); 143ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 144ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName = *szPropName; 145ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 146ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); 147ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(info.This()); 148ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpNewValue->ForceSetValue(info[0]); 149ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropSetterAdapter( 150ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, 151ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HVALUE>(lpNewValue)); 152ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 153ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 154ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpNewValue; 155ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpNewValue = nullptr; 156ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 157ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor( 158ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 159ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 160ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 161ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!lpClass) { 162ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return; 163ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 164ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 165ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 166ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = info[0]->ToString(); 167ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 168ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 169ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate = 170ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::ObjectTemplate::New(); 171ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfoTemplate->SetInternalFieldCount(2); 172ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hCallBackInfo = hCallBackInfoTemplate->NewInstance(); 173ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->SetAlignedPointerInInternalField( 174ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 0, const_cast<FXJSE_CLASS*>(lpClass)); 175ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo->SetInternalField(1, hPropName); 176ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hPropDescriptor = v8::Object::New(pIsolate); 177ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hPropDescriptor->ForceSet( 178ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "get"), 179ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, 180ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter, 181ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo)); 182ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hPropDescriptor->ForceSet( 183ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "set"), 184ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, 185ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter, 186ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hCallBackInfo)); 187ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "enumerable"), 188ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Boolean::New(pIsolate, false)); 189ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "configurable"), 190ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Boolean::New(pIsolate, true)); 191ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(hPropDescriptor); 192ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 193ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getPropertyDescriptor( 194ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 195ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 196ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hChainObj = 197ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.This()->GetPrototype().As<v8::Object>(); 198ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Script> fnSource = v8::Script::Compile(v8::String::NewFromUtf8( 199ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann pIsolate, 200ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann "(function (o, name) { var fn, x, d; fn = " 201ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann "Object.getOwnPropertyDescriptor; x = o; while(x && !(d = fn(x, " 202ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann "name))){x = x.__proto__;} return d; })")); 203ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Function> fn = fnSource->Run().As<v8::Function>(); 204ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> rgArgs[] = {hChainObj, info[0]}; 205ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> hChainDescriptor = fn->Call(info.This(), 2, rgArgs); 206ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!hChainDescriptor.IsEmpty() && hChainDescriptor->IsObject()) { 207ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(hChainDescriptor); 208ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } else { 209ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_V8ProxyCallback_getOwnPropertyDescriptor(info); 210ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 211ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 212ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getOwnPropertyNames( 213ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 214ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 215ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 216ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(v8::Array::New(pIsolate)); 217ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 218ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_getPropertyNames( 219ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 220ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hChainObj = 221ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.This()->GetPrototype().As<v8::Object>(); 222ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> hChainPropertyNames = hChainObj->GetPropertyNames(); 223ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(hChainPropertyNames); 224ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 225ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_defineProperty( 226ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 227ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 228ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 229ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!lpClass) { 230ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return; 231ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 232ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 233ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 234ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = info[0]->ToString(); 235ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hPropDescriptor = info[1]->ToObject(); 236ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 237ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!hPropDescriptor->Has(v8::String::NewFromUtf8(pIsolate, "value"))) { 238ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return; 239ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 240ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> hPropValue = 241ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hPropDescriptor->Get(v8::String::NewFromUtf8(pIsolate, "value")); 242ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 243ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 244ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); 245ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(info.This()); 246ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpPropValue->ForceSetValue(hPropValue); 247ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropSetterAdapter( 248ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, 249ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HVALUE>(lpPropValue)); 250ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 251ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 252ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpPropValue; 253ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpPropValue = nullptr; 254ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 255ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_delete( 256ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 257ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(true); 258ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 259ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 260ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (!lpClass) { 261ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann return; 262ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 263ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 264ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 265ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::String> hPropName = info[0]->ToString(); 266ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(hPropName); 267ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 268ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 269ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(info.This()); 270ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set( 271ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropDeleterAdapter( 272ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName) 273ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? true 274ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : false); 275ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 276ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 277ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 278ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8ProxyCallback_fix( 279ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::FunctionCallbackInfo<v8::Value>& info) { 280ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().SetUndefined(); 281ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 282ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8_GenericNamedPropertyQueryCallback( 283ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Name> property, 284ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::PropertyCallbackInfo<v8::Integer>& info) { 285ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> thisObject = info.This(); 286ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 287ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 288ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 289ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 290ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(property); 291ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 292ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 293ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(thisObject); 294ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann if (FXJSE_DynPropQueryAdapter(lpClass, 295ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), 296ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann szFxPropName)) { 297ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(v8::DontDelete); 298ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } else { 299ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const int32_t iV8Absent = 64; 300ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(iV8Absent); 301ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 302ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 303ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 304ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 305ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8_GenericNamedPropertyDeleterCallback( 306ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Name> property, 307ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::PropertyCallbackInfo<v8::Boolean>& info) { 308ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> thisObject = info.This(); 309ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 310ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 311ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 312ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::HandleScope scope(pIsolate); 313ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(property); 314ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 315ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 316ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(thisObject); 317ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set( 318ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropDeleterAdapter( 319ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName) 320ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? true 321ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : false); 322ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 323ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 324ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 325ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8_GenericNamedPropertyGetterCallback( 326ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Name> property, 327ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::PropertyCallbackInfo<v8::Value>& info) { 328ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> thisObject = info.This(); 329ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 330ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 331ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(property); 332ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 333ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 334ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(thisObject); 335ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); 336ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropGetterAdapter( 337ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, 338ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HVALUE>(lpNewValue)); 339ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(lpNewValue->DirectGetValue()); 340ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 341ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 342ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 343ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8_GenericNamedPropertySetterCallback( 344ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Name> property, 345ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> value, 346ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::PropertyCallbackInfo<v8::Value>& info) { 347ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> thisObject = info.This(); 348ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 349ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 350ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::Utf8Value szPropName(property); 351ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); 352ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); 353ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue->ForceSetValue(thisObject); 354ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); 355ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpNewValue->ForceSetValue(value); 356ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_DynPropSetterAdapter( 357ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, 358ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann reinterpret_cast<FXJSE_HVALUE>(lpNewValue)); 359ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(value); 360ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann delete lpThisValue; 361ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpThisValue = nullptr; 362ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 363ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannstatic void FXJSE_V8_GenericNamedPropertyEnumeratorCallback( 364ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const v8::PropertyCallbackInfo<v8::Array>& info) { 365ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClass = 366ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); 367ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = info.GetIsolate(); 368ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Array> newArray = v8::Array::New(pIsolate, lpClass->propNum); 369ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann for (int i = 0; i < lpClass->propNum; i++) { 370ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann newArray->Set( 371ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann i, v8::String::NewFromUtf8(pIsolate, lpClass->properties[i].name)); 372ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann } 373ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann info.GetReturnValue().Set(newArray); 374ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 375ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann 376ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannvoid CFXJSE_Class::SetUpDynPropHandler(CFXJSE_Context* pContext, 377ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_Value* pValue, 378ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClassDefinition) { 379ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate = pValue->GetIsolate(); 380ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext scope(pIsolate, pContext); 381ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Context> hContext = v8::Local<v8::Context>::New( 382ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann pIsolate, pContext ? pContext->m_hContext 383ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); 384ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hObject = 385ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value>::New(pIsolate, pValue->m_hValue).As<v8::Object>(); 386ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hHarmonyProxyObj = 387ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hContext->Global() 388ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ->Get(v8::String::NewFromUtf8(pIsolate, "Proxy")) 389ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann .As<v8::Object>(); 390ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Function> hHarmonyProxyCreateFn = 391ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hHarmonyProxyObj->Get(v8::String::NewFromUtf8(pIsolate, "create")) 392ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann .As<v8::Function>(); 393ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> hOldPrototype = hObject->GetPrototype(); 394ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Object> hTrapper = v8::Object::New(pIsolate); 395ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 396ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "getOwnPropertyDescriptor"), 397ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New( 398ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyDescriptor, 399ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, 400ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const_cast<FXJSE_CLASS*>(lpClassDefinition)))); 401ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 402ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "getPropertyDescriptor"), 403ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyDescriptor, 404ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 405ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 406ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 407ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "getOwnPropertyNames"), 408ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyNames, 409ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 410ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 411ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 412ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "getPropertyNames"), 413ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyNames, 414ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 415ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 416ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 417ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "delete"), 418ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_delete, 419ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 420ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 421ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 422ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "defineProperty"), 423ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_defineProperty, 424ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 425ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 426ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hTrapper->ForceSet( 427ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::String::NewFromUtf8(pIsolate, "fix"), 428ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_fix, 429ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( 430ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition)))); 431ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> rgArgs[] = {hTrapper, hOldPrototype}; 432ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::Value> hNewPrototype = 433ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hHarmonyProxyCreateFn->Call(hHarmonyProxyObj, 2, rgArgs); 434ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hObject->SetPrototype(hNewPrototype); 435ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 436ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannvoid CFXJSE_Class::SetUpNamedPropHandler( 437ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Isolate* pIsolate, 438ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::Local<v8::ObjectTemplate>& hObjectTemplate, 439ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann const FXJSE_CLASS* lpClassDefinition) { 440ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::NamedPropertyHandlerConfiguration configuration( 441ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition->dynPropGetter 442ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_V8_GenericNamedPropertyGetterCallback 443ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : 0, 444ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition->dynPropSetter 445ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_V8_GenericNamedPropertySetterCallback 446ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : 0, 447ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition->dynPropTypeGetter 448ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_V8_GenericNamedPropertyQueryCallback 449ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : 0, 450ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann lpClassDefinition->dynPropDeleter 451ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann ? FXJSE_V8_GenericNamedPropertyDeleterCallback 452ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann : 0, 453ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann FXJSE_V8_GenericNamedPropertyEnumeratorCallback, 454ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition)), 455ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann v8::PropertyHandlerFlags::kNonMasking); 456ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann hObjectTemplate->SetHandler(configuration); 457ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann} 458