Invoke function by proxy - coldfusion

I am trying to create a cf component to proxy another one. At the moment the code looks like this: (stripped down for the sake of example):
public MyFuseboxProxy function init( Required any myFb ){
variables.myFusebox = arguments.myFb;
return this;
}
this.do = variables.proxy;
private any function proxy(){
var local.functionName = getFunctionCalledName();
var local.function = variables.myFusebox[local.functionName];
var local.returnVal = local.function( arguments );
...
}
As you can see, it's quite straight forward. I pass in my target object at initialisation then use the proxy method to intercept function calls. I am using cfscript, and don't want to use cfinvoke, so am using this approach.
I then call the proxy as follows:
var local.proxy = new ab.MyFuseboxProxy( myFusebox );
var local.dump = local.proxy.do ( action='display.body', contentvariable="body" );
However, when I execute the above code I get the following error:
The ACTION argument passed to the do function is not of type string.
If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be
found or is not accessible.
The error occurred in C:/ColdFusion10/cfusion/wwwroot/fusebox5/myFusebox.cfc: line 301
The error is reported on the target component, so it seems like the function is being called, and the arguments passed through, but the type is not being preserved/recognised as a String.
Can anyone advise what I am doing wrong or how I can preserve the argument types?

Yup, I suspect instead of this:
var local.returnVal = local.function( arguments );
You mean this:
var local.returnVal = local.function(argumentCollection=arguments );
Your current code is passing the arguments as the first argument, rather than passing them as they were originally passed in.

Related

readLine(prompt =) use in shiny

Can readLines(prompt = ...) be used in any way in shiny?
Suppose the following: in the server, inside a renderPrint component I will use shinijs::display("takeInput). This GUI component takes input from the user, so I will pass the input to a function by means of the function call. Afterwards, the function calls another function and sends the input to that function. The input will be received and tested by the second function. The result of the test will be returned to the first function which will return it to the server. Please see below:
Is there another way to do this? A simpler way? I do not see the way of doing it by just using readLine(promp = ..) in the second function. I do not see how this can be compatible with shiny.
ui{
selectInput("xxxxx")
verbatimTextOutput(
}
source(program containing functionName)
source(program containing another function name)
functionName <- function(parameters, takeInput){
functionName2 <- anotherFunctionName(parameters, takeInput)
functionName2 <- valueOfFunctionName2
if(functionName2 == xx){
dosomthing
return the value to the server
list(functionName2 = functionName2)
}
anotherFunctionName<- function(parameters, takeInput){
if(takeInput == something){
return the value of anotherFunctionName to functionName which will return it to the server
valueOfFunctionName2
}
}

Using onMissingMethod cannot access object variables

In CF10, I want to access a variable Test object using onMissingMethod function in TestHelper object, but I am getting an error.
Test.cfc
component {
public Any function init(){
instance = { x = 1 };
return this;
}
public numeric function getX(){
return instance.x;
}
}
TestHelper.cfc
component {
public Any function init( ){
variables.testObj = new Test();
return this;
}
public any function onMissingMethod( required string missingMethodName, required struct missingMethodArguments ){
var func = variables.testObj[ arguments.missingMethodName ];
return func( argumentCollection = arguments.missingMethodArguments );
}
}
Calling the object
obj = new TestHelper();
writeOutput( obj.getX() ); //Element INSTANCE.X is undefined in VARIABLES
In CF10, this gives me an error that element X is undefined in instance. It doesn't seem to recognize the variable instance. I could explicitly define getX function in TestHelper, but I was hoping I could use the onMissingMethod function.
Am I misunderstanding how onMissingMethod supposed to work here? FWIW, the code works in Railo.
If I understand your issue, I'm surprised this code runs on Railo. I don't think it should.
The issue is with this code:
var func = variables.testObj[ arguments.missingMethodName ];
return func( argumentCollection = arguments.missingMethodArguments );
Here you are pulling the function getX() out of variables.testObj, and running it in the context of your TestHelper instance. And that object doesn't have a `variables.x. Hence the error.
You need to put your func reference into variables.testObj, not pull getX out of it. So like this:
var variables.testObj.func = variables.testObj[ arguments.missingMethodName ];
return variables.testObj.func( argumentCollection = arguments.missingMethodArguments );
That way you're running func() (your proxy to getX()) in the correct context, so it will see variabales.x.
Given this situation, there's no way this code should work on Railo (based on the info you've given us being all the relevant info, anyhow).

How do I get a custom element definition without instantiating it?

After looking at the custom element spec, it's not immediately obvious how I get a reference to a custom element definition without first instantiating it (which can be problematic). Is there a way to directly reference a custom element's prototype?
More concretely, if I have:
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() { // some heavy operation };
document.registerElement('x-foo', {prototype: proto});
At some point later, I would love to reference the prototype with something like:
// wish
var XFoo = document.getElementDefinition('x-foo');
But instead the only way I've come up with is:
// reality
var XFoo = document.createElement('x-foo').__proto__;
This is especially problematic when trying to write tests against heavy components - as there's no way to stub out the heavy behavior (with something like XFoo.createdCallback = // stub; before the original method is actually called.
If you have reference to the constructor of the custom element, you can use it to access the prototype.
var XFoo = document.registerElement('x-foo', {prototype: proto});
XFoo.prototype // this will give u access to the prototype object.
there's no way to stub out the heavy behavior
Use a function reference rather than an anonymous function:
proto.createdCallback = model.foo;
define it:
var model = {};
model.foo = function(){/*some heavy operation*/};
then stub it by redefining it:
var XModel = {};
XModel.foo = function(){/*stub*/};
and reference it in the test:
XFoo.createdCallback = XModel.foo;
References
AOP Aspect of JavaScript
AJAX Interception
Intro to Aspect Oriented Programming

accessing function parameters registers for load

functions are created like this:
llvm::FunctionType* FunctionTypePtr = llvm::FunctionType::get( returnTypePtr , types , false );
llvm::Function* llvmFunction = llvm::Function::Create(FunctionTypePtr,
llvm::GlobalValue::ExternalLinkage,
functionName,
llvmModule);
then the body of the function is created by adding instructions to the block:
llvm::BasicBlock* entryBlock = llvm::BasicBlock::Create(llvmContext, "", llvmFunction);
llvm::IRBuilder<> builder(entryBlock);
Enough context, now to the problem: I want to add load instructions for the function argument values, like:
//where do i get address??
llvm::LoadInst* load = builder.CreateLoad(address, "read");
I don't know how/where to grab the address variable for a function parameter.
You should not load anything. Use Function::arg_iterator to get the Value's corresponding to the arguments.
See http://llvm.org/docs/doxygen/html/classllvm_1_1Function.html (arg_begin / arg_end) and http://llvm.org/docs/ProgrammersManual.html#Function for more information

TypeError: Error #1010: web service as3 + wcf

I have a simple webservice returning object list of books. I am trying to take this collection with aducentes web service class, but I get the type error:
TypeError: Error #1010: A term is undefined and has no properties.
Can anyone help to pull object into
array and trace the result?
import alducente.services.WebService;
import flash.events.*;
var ws:WebService = new WebService();
ws.addEventListener(Event.CONNECT, connected);
ws.connect("http://localhost:8732/Design_Time_Addresses/TestService/Service1/?wsdl");
ws.cacheResults = true;
var initTime:Number;
function connected(evt:Event):void{
// var books:Array=ws.IBookService.GetBooks();
// trace(books[0]);
var obj:Object=ws.IBookService.GetBooks();
// var obj:Object=ws.IBookService.GetBooks();
// trace(obj[0].toString());
}
Just thought of something else... In the version of WebService I used a while back, you have to specify a resultHandler function with each method call:
function connected(evt:Event):void{
ws.IBookService.GetBooks( getBooksResultHandler );
}
function getBooksResultHandler( resultXML : XML ) : void {
doStuffWith(resultXML);
}
The result will be passed to the handler you've passed as a parameter.