From 86b55046c96d9c450a31397cac6465c6c9224962 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Tue, 9 Jul 2019 12:40:20 +0100 Subject: [PATCH] In JSInterop calls, use expected value for 'this'. Fixes dotnet/extensions#1477 (dotnet/extensions#1990) \n\nCommit migrated from https://github.com/dotnet/extensions/commit/a664ecb5b3bcf9b2fdeb272e5e2705e8e43eeb9c --- .../src/src/Microsoft.JSInterop.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts b/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts index 5386b92bb5..2b3f51300c 100644 --- a/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts +++ b/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts @@ -141,14 +141,6 @@ module DotNet { * Receives incoming calls from .NET and dispatches them to JavaScript. */ 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. * @@ -227,8 +219,10 @@ module DotNet { let result: any = window; let resultIdentifier = 'window'; + let lastSegmentValue: any; identifier.split('.').forEach(segment => { if (segment in result) { + lastSegmentValue = result; result = result[segment]; resultIdentifier += '.' + segment; } else { @@ -237,6 +231,8 @@ module DotNet { }); if (result instanceof Function) { + result = result.bind(lastSegmentValue); + cachedJSFunctions[identifier] = result; return result; } else { throw new Error(`The value '${resultIdentifier}' is not a function.`);