Permalink
Browse files

Added TryInvoke dynamic binding function to JSValue

Signed-off-by: Peter Nelson <peter@peterdn.com>
  • Loading branch information...
1 parent 423582a commit 5a67dae661c15f9da92ec57f13ff3f83d4c8a402 @peterdn peterdn committed Mar 28, 2013
Showing with 22 additions and 13 deletions.
  1. +5 −10 JSCore/JSObject.cpp
  2. +1 −1 JSCore/JSObject.h
  3. +9 −0 JSCore/JSValue.cpp
  4. +1 −0 JSCore/JSValue.h
  5. +6 −2 WebKitBrowserTest/MainForm.cs
View
15 JSCore/JSObject.cpp
@@ -72,29 +72,24 @@ void JSObject::SetProperty(String ^ propertyName, ActionDelegate ^ func)
SetProperty(propertyName, jsVal);
}
-JSValue ^ JSObject::CallAsFunction(JSContext ^ context, array<Object ^> ^ variableArgs)
+JSValue ^ JSObject::CallAsFunction(array<Object ^> ^ variableArgs)
{
JSContextRef ctx = _context->context();
- JSContextRef ctxworks = context->context();
-
- if (ctx == ctxworks) {
- float i = 2;
- }
JSValueRef * args = new JSValueRef[variableArgs->Length];
for(int i = 0; i < variableArgs->Length; i++)
{
- args[i] = getJSValueRefFromObject(context->context(), variableArgs[i], NULL);
+ args[i] = getJSValueRefFromObject(ctx, variableArgs[i], NULL);
}
- JSValueRef ret = JSObjectCallAsFunction(context->context(), (JSObjectRef)_value, NULL, variableArgs->Length, args, NULL);
+ JSValueRef ret = JSObjectCallAsFunction(ctx, (JSObjectRef)_value, NULL, variableArgs->Length, args, NULL);
for(int i = 0; i < variableArgs->Length; i++)
{
- JSValueUnprotect(context->context(), args[i]);
+ JSValueUnprotect(ctx, args[i]);
}
delete[] args;
- return gcnew JSValue(context, ret);
+ return gcnew JSValue(_context, ret);
}
JSValue ^ JSObject::CallFunction(String ^ methodName, ... array<Object ^> ^ variableArgs)
View
2 JSCore/JSObject.h
@@ -31,7 +31,7 @@ public ref class JSObject : public WebKit::JSCore::JSValue
void SetProperty(String ^ propertyName, System::String ^ value);
void SetProperty(String ^ propertyName, EventDelegate ^ func);
void SetProperty(String ^ propertyName, ActionDelegate ^ func);
- JSValue ^ JSObject::CallAsFunction(JSContext ^ context, array<Object ^> ^ variableArgs);
+ JSValue ^ CallAsFunction(array<Object ^> ^ variableArgs);
JSValue ^ CallFunction(String ^ methodName, ... array<Object ^> ^ variableArgs);
Dictionary<Object^, Object^>^ ToDictionary();
View
9 JSCore/JSValue.cpp
@@ -188,5 +188,14 @@ bool JSValue::TryInvokeMember(System::Dynamic::InvokeMemberBinder ^ binder, arra
result = obj->CallFunction(binder->Name, args);
return true;
}
+
+bool JSValue::TryInvoke(System::Dynamic::InvokeBinder^ binder, array<Object ^> ^ args, [OutAttribute] Object ^% result)
+{
+ if (!IsObject) return false;
+ JSObject ^ obj = ToObject();
+ result = obj->CallAsFunction(args);
+ return true;
+}
+
#endif
View
1 JSCore/JSValue.h
@@ -51,6 +51,7 @@ public ref class JSValue
virtual bool TryGetMember(System::Dynamic::GetMemberBinder^ binder, [OutAttribute] Object ^% result) override;
virtual bool TrySetMember(System::Dynamic::SetMemberBinder^ binder, Object ^ result) override;
virtual bool TryInvokeMember(System::Dynamic::InvokeMemberBinder^ binder, array<Object ^> ^ args, [OutAttribute] Object ^% result) override;
+ virtual bool TryInvoke(System::Dynamic::InvokeBinder^ binder, array<Object ^> ^ args, [OutAttribute] Object ^% result) override;
#endif
internal:
View
8 WebKitBrowserTest/MainForm.cs
@@ -291,13 +291,17 @@ private void jSTestPageToolStripMenuItem_Click(object sender, EventArgs e)
private void test3ToolStripMenuItem_Click(object sender, EventArgs e)
{
- JSContext ctx = (JSContext)currentPage.browser.GetGlobalScriptContext();
+ JSContext ctx = (JSContext) currentPage.browser.GetGlobalScriptContext();
+ var window = ctx.GetGlobalObject();
+ dynamic doStuff = window.GetProperty("doStuff");
+ doStuff("hello!");
+ /*JSContext ctx = (JSContext)currentPage.browser.GetGlobalScriptContext();
TestClass myTest = new TestClass()
{
ctx = ctx
};
- currentPage.browser.ObjectForScripting = myTest;
+ currentPage.browser.ObjectForScripting = myTest;*/
//ctx.EvaluateScript("test()");

0 comments on commit 5a67dae

Please sign in to comment.