zoukankan      html  css  js  c++  java
  • javascript sandbox

    用途

    https://github.com/gf3/sandbox

    • Can be used to execute untrusted code.
    • Support for timeouts (e.g. prevent infinite loops)
    • Support for memory errors (and memory errors)
    • Handles errors gracefully
    • Restricted code (cannot access node.js methods)
    • Supports console.log and print utility methods
    • Supports interprocess messaging with the sandboxed code

    例子

    https://github.com/gf3/sandbox/blob/master/example/example.js

    var Sandbox = require("../lib/sandbox")
      , s = new Sandbox()

    // Example 1 - Standard JS
    s.run( "1 + 1", function( output ) {
      console.log( "Example 1: " + output.result + " " )
    })

    通信

    箱内和向外相互通信。

    Sandboxed code:

    onmessage = function(message){
      if (message === 'hello from outside') {
        postMessage('hello from inside');
      }
    };

    Sandbox:

    var sandbox = new Sandbox();
    sandbox.run(sandboxed_code);
    sandbox.on('message', function(message){
      // Handle message sent from the inside
      // In this example message will be 'hello from inside'
    });
    sandbox.postMessage('hello from outside');
    
    // Example 11 - IPC Messaging
    s.run( "onmessage = function(message){ if (message === 'hello from outside') { postMessage('hello from inside'); };", function(output){
      
    })
    s.on('message', function(message){
      console.log("Example 11: received message sent from inside the sandbox '" + message + "'
    ")
    });
    var test_message = "hello from outside";
    console.log("Example 11: sending message into the sandbox '" + test_message + "'");
    s.postMessage(test_message);
  • 相关阅读:
    进程、线程
    timer控件、三级联动
    用户控件、动态创建添加
    打印控件
    窗体移动和阴影,对话框控件
    winform listview控件
    winform打开唯一窗体、构造函数传值
    菜单和工具栏
    winform公共控件
    hibernate中各种包的添加
  • 原文地址:https://www.cnblogs.com/lightsong/p/6100020.html
Copyright © 2011-2022 走看看