Make wrapper objects contain references to the Properties/Methods they represent

This commit is contained in:
amaitland
2014-08-28 15:27:06 +10:00
parent d0dc5d9409
commit 0130fa427d
13 changed files with 102 additions and 128 deletions
@@ -4,6 +4,10 @@
#pragma once
#include "Stdafx.h"
#include "include/cef_app.h"
#include "include/cef_base.h"
#include "include/cef_v8.h"
#include "JavascriptObjectWrapper.h"
#include "JavascriptMethodHandler.h"
@@ -12,28 +16,30 @@ using namespace System::Runtime::Serialization;
namespace CefSharp
{
private ref class JavascriptMethodWrapper : IBindableJavascriptMember
public ref class JavascriptMethodWrapper
{
private:
MCefRefPtr<JavascriptMethodHandler> _javascriptMethodHandler;
JavascriptObjectWrapper^ _owner;
JavascriptMethod^ _method;
JavascriptMethod^ _javascriptMethod;
int _ownerId;
internal:
MCefRefPtr<CefV8Value> V8Value;
public:
JavascriptMethodWrapper(JavascriptMethod^ method)
JavascriptMethodWrapper(JavascriptMethod^ javascriptMethod, int ownerId)
{
_method = method;
_javascriptMethod = javascriptMethod;
_ownerId = ownerId;
_javascriptMethodHandler = new JavascriptMethodHandler(gcnew Func<array<Object^>^, Object^>(this, &JavascriptMethodWrapper::Execute));
}
virtual void Bind(JavascriptObject^ owner)
virtual void Bind()
{
_owner = static_cast<JavascriptObjectWrapper^>(owner);
auto methodName = StringUtils::ToNative(_method->JavascriptName);
auto methodName = StringUtils::ToNative(_javascriptMethod->JavascriptName);
auto v8Value = CefV8Value::CreateFunction(methodName, _javascriptMethodHandler.get());
_owner->V8Value->SetValue(methodName, v8Value, V8_PROPERTY_ATTRIBUTE_NONE);
V8Value->SetValue(methodName, v8Value, V8_PROPERTY_ATTRIBUTE_NONE);
};
Object^ Execute(array<Object^>^ parameters);