diff --git a/core/app.js b/core/app.js index 8083fb3d..7a809a8f 100644 --- a/core/app.js +++ b/core/app.js @@ -1,7 +1,5 @@ -"use strict"; - -var auth = require('auth'); -var core = require('core'); +import * as auth from './auth.js'; +import * as core from './core.js'; var gSessionIndex = 0; @@ -164,5 +162,4 @@ function socket(request, response, client) { } } -exports.socket = socket; -exports.App = App; +export { socket, App }; diff --git a/core/auth.js b/core/auth.js index 637c4879..7b3adf93 100644 --- a/core/auth.js +++ b/core/auth.js @@ -1,11 +1,8 @@ -"use strict"; +import * as core from './core.js'; +import * as http from './http.js'; +import * as form from './form.js'; var gTokens = {}; - -var core = require('core'); -var form = require('form'); -var http = require('http'); - var gDatabase = new Database("auth"); function readSession(session) { @@ -86,7 +83,7 @@ function getCookies(headers) { return cookies; } -function authHandler(request, response) { +function handler(request, response) { var session = getCookies(request.headers).session; if (request.uri == "/login") { var sessionIsNew = false; @@ -219,5 +216,4 @@ function query(headers) { } } -exports.handler = authHandler; -exports.query = query; +export { handler, query }; diff --git a/core/core.js b/core/core.js index 805ad495..e26ad380 100644 --- a/core/core.js +++ b/core/core.js @@ -1,7 +1,6 @@ -"use strict"; - -var auth = require("auth"); -var app = require("app"); +import * as auth from './auth.js'; +import * as app from './app.js'; +import * as httpd from './httpd.js'; var gProcessIndex = 0; var gProcesses = {}; @@ -559,8 +558,6 @@ function enableStats(process, enabled) { } loadSettings().then(function() { - var auth = require("auth"); - var httpd = require("httpd"); httpd.all("/login", auth.handler); httpd.all("", function(request, response) { var match; @@ -600,12 +597,14 @@ loadSettings().then(function() { httpd.registerSocketHandler("/app/socket", app.socket); }).catch(function(error) { print('Failed to load settings.'); - print(error); + printError({print: print}, error); exit(1); }); -exports.getSessionProcessBlob = getSessionProcessBlob; -exports.invoke = invoke; -exports.globalSettings = gGlobalSettings; -exports.setGlobalSettings = setGlobalSettings; -exports.enableStats = enableStats; +export { + gGlobalSettings as globalSettings, + setGlobalSettings, + enableStats, + invoke, + getSessionProcessBlob +}; diff --git a/core/form.js b/core/form.js index 4849f0f2..b40def3a 100644 --- a/core/form.js +++ b/core/form.js @@ -1,5 +1,3 @@ -"use strict"; - function decode(encoded) { var result = ""; for (var i = 0; i < encoded.length; i++) { @@ -32,4 +30,4 @@ function decodeForm(encoded, initial) { return result; } -exports.decodeForm = decodeForm; +export { decodeForm }; diff --git a/core/http.js b/core/http.js index aaf92a65..9cf5d1b8 100644 --- a/core/http.js +++ b/core/http.js @@ -31,7 +31,7 @@ function parseResponse(data) { return {body: data}; } -function get(url) { +export function get(url) { var parsed = parseUrl(url); return new Promise(function(resolve, reject) { var socket = new Socket(); @@ -57,5 +57,3 @@ function get(url) { }); }); } - -exports.get = get; diff --git a/core/httpd.js b/core/httpd.js index cbdbfb72..5cd48aa3 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -1,3 +1,5 @@ +import * as sha1 from './sha1.js'; + "use strict"; var gHandlers = []; @@ -332,7 +334,7 @@ function handleWebSocketRequest(request, response, client) { function webSocketAcceptResponse(key) { var kMagic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; var kAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - var hex = require("sha1").hash(key + kMagic) + var hex = sha1.hash(key + kMagic) var binary = ""; for (var i = 0; i < hex.length; i += 6) { var characters = hex.substring(i, i + 6); @@ -634,5 +636,4 @@ if (tildefriends.https_port) { }); } -exports.all = all; -exports.registerSocketHandler = registerSocketHandler; +export { all, registerSocketHandler }; diff --git a/core/sha1.js b/core/sha1.js index 995b218b..3bf79c95 100644 --- a/core/sha1.js +++ b/core/sha1.js @@ -157,4 +157,4 @@ if (typeof String.prototype.utf8Decode == 'undefined') { if (typeof module != 'undefined' && module.exports) module.exports = Sha1; // CommonJs export if (typeof define == 'function' && define.amd) define([], function() { return Sha1; }); // AMD -exports.hash = Sha1.hash; +export let hash = Sha1.hash; diff --git a/src/task.c b/src/task.c index c744fd1d..6e364825 100644 --- a/src/task.c +++ b/src/task.c @@ -1044,7 +1044,7 @@ JSValue _tf_task_require(JSContext* context, JSValueConst this_val, int argc, JS }; task->_scriptExports = export; const char* source = _task_loadFile(path); - printf("Requiring script %s\n", path); + printf("Requiring script %sn", path); if (source) { JSValue global = JS_GetGlobalObject(task->_context); @@ -1408,17 +1408,26 @@ JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name, { tf_task_t* task = opaque; JSValue source_value = JS_GetPropertyStr(context, task->_loadedFiles, module_name); - char* source = NULL; size_t length = 0; - uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value); - if (array) + + if (!JS_IsUndefined(source_value)) { - source = tf_malloc(length + 1); - memcpy(source, array, length); - source[length] = '\0'; + uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value); + if (array) + { + source = tf_malloc(length + 1); + memcpy(source, array, length); + source[length] = '\0'; + } + JS_FreeValue(context, source_value); + } + + if (!source && task->_trusted) + { + source = (char*)_task_loadFile(module_name); + length = source ? strlen(source) : 0; } - JS_FreeValue(context, source_value); if (!source) {