Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions models/Component.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,13 @@ component output="true" accessors="true" {
}
arguments.calls.each( function( call ) {
try {
// Skip calls to methods the component does not expose. Embedded
// browsers/WebViews and extensions sometimes serialize the $wire
// object and inject noise calls (e.g. the standard JS "toJSON"),
// which would otherwise hit onMissingMethod() and throw a 500.
if( !structKeyExists( this, arguments.call.method ) ){
return;
}
if( _securedAnnotationAllows( arguments.call.method ) ){
local.result = invoke( this, arguments.call.method, arguments.call.params );
// Capture the return value in case it's needed by the front-end
Expand Down
31 changes: 31 additions & 0 deletions test-harness/tests/specs/unit/ComponentSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ component extends="coldbox.system.testing.BaseTestCase" {

});

describe( "_applyCalls()", function() {

it( "skips calls to methods the component does not expose without throwing", function() {
variables.wireComponent.$property( propertyName="_returnValues", mock=[] );

// "toJSON" is the standard JS method injected by some WebViews
// when they serialize the $wire object; no component defines it.
expect( function(){
variables.wireComponent._applyCalls( [
{ "method": "toJSON", "params": [] }
] );
} ).notToThrow();

expect( variables.wireComponent.$getProperty( "_returnValues" ) ).toBeEmpty();
});

it( "invokes existing methods and captures their return value", function() {
variables.wireComponent.$property( propertyName="_returnValues", mock=[] );
variables.wireComponent.$( "increment", "done" );

variables.wireComponent._applyCalls( [
{ "method": "increment", "params": [] }
] );

var returns = variables.wireComponent.$getProperty( "_returnValues" );
expect( returns ).toHaveLength( 1 );
expect( returns[ 1 ] ).toBe( "done" );
});

});

});
}

Expand Down
Loading