diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index 15973ab..3fc03e9 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -43,7 +43,7 @@ public class ScriptEngine { @SneakyThrows public void disableEngine() { - engine.invokeFunction("disable"); + engine.invokeFunction("engineDisable"); } public MiaoScriptEngine getEngine() { diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index 6c3d502..3ab460d 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -35,9 +35,13 @@ * 初始化模块 */ function loadRequire() { + global.engineLoad = load; + global.load = function __denyGlobalLoad__() { + throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !'); + } // 初始化加载器 - global.require = load(root + '/core/require.js')(root); - global.requireInternal = function (name) { + global.require = engineLoad(root + '/core/require.js')(root); + global.requireInternal = function requireInternal(name) { return require(root + '/internal/' + DetectServerType + '/' + name + '.js'); } } @@ -61,16 +65,16 @@ */ function loadServerLib() { var task = require('api/task'); - global.setTimeout = function (func, time, _async) { + global.setTimeout = function setTimeout(func, time, _async) { return _async ? task.laterAsync(func, time) : task.later(func, time); }; - global.clearTimeout = function (task) { + global.clearTimeout = function clearTimeout(task) { task.cancel(); }; - global.setInterval = function (func, time, _async) { + global.setInterval = function setInterval(func, time, _async) { return _async ? task.timerAsync(func, time) : task.timer(func, time); }; - global.clearInterval = function (task) { + global.clearInterval = function clearInterval(task) { task.cancel(); }; } @@ -95,9 +99,9 @@ /** * 关闭插件Hook */ - global.disable = function disable() { + global.engineDisable = function disable() { if (global.manager && global.manager.$) { global.manager.disable(); } } -})(global); \ No newline at end of file +})(global); diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index ba7aa98..dc6ed15 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -204,7 +204,7 @@ } base.save(cacheFile, "(function __init__(module, exports, require, __dirname, __filename) {" + origin + "});"); // 使用 load 可以保留行号和文件名称 - var compiledWrapper = load(cacheFile); + var compiledWrapper = engineLoad(cacheFile); try { base.delete(cacheFile); } catch (ex) { @@ -267,4 +267,4 @@ var cacheModules = []; console.debug("初始化 require 模块组件 父目录 ", _canonical(parent)); return exports(parent); -}); \ No newline at end of file +});