In JSInterop calls, use expected value for 'this'. Fixes dotnet/extensions#1477 (dotnet/extensions#1990)
\n\nCommit migrated from a664ecb5b3
This commit is contained in:
parent
97a039f154
commit
86b55046c9
|
|
@ -141,14 +141,6 @@ module DotNet {
|
||||||
* Receives incoming calls from .NET and dispatches them to JavaScript.
|
* Receives incoming calls from .NET and dispatches them to JavaScript.
|
||||||
*/
|
*/
|
||||||
export const jsCallDispatcher = {
|
export const jsCallDispatcher = {
|
||||||
/**
|
|
||||||
* Finds the JavaScript function matching the specified identifier.
|
|
||||||
*
|
|
||||||
* @param identifier Identifies the globally-reachable function to be returned.
|
|
||||||
* @returns A Function instance.
|
|
||||||
*/
|
|
||||||
findJSFunction,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the specified synchronous JavaScript function.
|
* Invokes the specified synchronous JavaScript function.
|
||||||
*
|
*
|
||||||
|
|
@ -227,8 +219,10 @@ module DotNet {
|
||||||
|
|
||||||
let result: any = window;
|
let result: any = window;
|
||||||
let resultIdentifier = 'window';
|
let resultIdentifier = 'window';
|
||||||
|
let lastSegmentValue: any;
|
||||||
identifier.split('.').forEach(segment => {
|
identifier.split('.').forEach(segment => {
|
||||||
if (segment in result) {
|
if (segment in result) {
|
||||||
|
lastSegmentValue = result;
|
||||||
result = result[segment];
|
result = result[segment];
|
||||||
resultIdentifier += '.' + segment;
|
resultIdentifier += '.' + segment;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -237,6 +231,8 @@ module DotNet {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result instanceof Function) {
|
if (result instanceof Function) {
|
||||||
|
result = result.bind(lastSegmentValue);
|
||||||
|
cachedJSFunctions[identifier] = result;
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`The value '${resultIdentifier}' is not a function.`);
|
throw new Error(`The value '${resultIdentifier}' is not a function.`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue