示例#1
0
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (_disposedFlag.Set())
            {
                if (_dispatcher != null)
                {
                    _dispatcher.Invoke(() => _jsRuntime.Dispose());
                    _dispatcher.Dispose();
                }

                if (disposing)
                {
                    if (_externalObjects != null)
                    {
                        _externalObjects.Clear();
                    }

                    if (_nativeFunctions != null)
                    {
                        _nativeFunctions.Clear();
                    }

                    _externalObjectFinalizeCallback = null;
                }
            }
        }
示例#2
0
 private void DisposeUnmanagedResources()
 {
     if (_jsContext.IsValid)
     {
         _jsContext.Release();
     }
     _jsRuntime.Dispose();
 }
示例#3
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    typeMapper.Dispose();
                }
                var _programToDispose = programs.ToList();
                foreach (var program in _programToDispose)
                {
                    program.Dispose();
                }
                runtime.Dispose();

                disposedValue = true;
            }
        }
 public void Dispose()
 {
     typeMapper.Dispose();
     context.Release();
     runtime.Dispose();
 }
示例#5
0
        public void TestLateCallback()
        {
            IJsCallback callback;

            Action <IJsCallback, int> setTimer = (cb, ms) =>
            {
                Console.WriteLine("Adding Callback: {0}", ms);
                callback = cb;
            };
            var runtime = new JsRuntime();
            var context = NewTestExecutionContext(runtime);

            context.SetValue <Action <IJsCallback, int> >("setProxyTimeout",
                                                          (jsCallback, i) =>
            {
                jsCallback.Apply(this);
            });
            context.RunScript(string.Empty, @"
'use strict';

class JsElementApi {
    constructor() {

    }

    doThing() {
        console.log('doThing()');
    }

    toString() {
        return '[JsElementApi]';
    }
}


class AnotherContext {
    constructor() {

    }
    toString() {
        return '[AnotherContext]';
    }
}

var another = new AnotherContext();
//function setProxyTimeout(fn, to) {
    //setTimeout(function() {
//        fn.apply(another);
    //}, to);
//}

// thisBinding
var thisBinding = new JsElementApi();
var module_1234 = { };

// RunScript(string.Empty, Program)
(function(module) {
    const self = this;

    var foo = 'Hello World';

    function enter() {
        start = start.bind(this);
        console.log('enter()');
        setProxyTimeout(start, 1000);
    }

    function start() {
        console.log(this.toString());
        console.log(foo);
    }

    function update() {
        console.log('update()');
    }

    function exit() {
        console.log('exit');
    }

    function msgMissing() {
        console.log('msgMissing');
    }

    if (typeof module !== 'undefined') {
        module.exports = {
            enter: enter,
            update: update,
            exit: exit,
            msgMissing: msgMissing
        };
    }

}).call(thisBinding, module_1234);

// Assuming thisBinding is global
// GetFunction('enter'), etc...
var enter = module_1234.exports.enter;
var update = module_1234.exports.update;
var exit = module_1234.exports.exit;
var msgMissing = module_1234.exports.msgMissing;

enter.apply(thisBinding);
");
            runtime.Dispose();
        }