diff --git a/examples/pxScene2d/src/rcvrcore/AppSceneContext.js b/examples/pxScene2d/src/rcvrcore/AppSceneContext.js index d0efd9402e..d2089f1496 100644 --- a/examples/pxScene2d/src/rcvrcore/AppSceneContext.js +++ b/examples/pxScene2d/src/rcvrcore/AppSceneContext.js @@ -686,7 +686,7 @@ AppSceneContext.prototype.include = function(filePath, currentXModule) { onImportComplete([modData, origFilePath]); return; } else if (filePath === 'http' || filePath === 'https') { - var accessControl = (isV8 || isDuk) ? null : _this.accessControl; + var accessControl = _this.accessControl; modData = filePath === 'http' ? new http_wrap(accessControl) : new https_wrap(accessControl); onImportComplete([modData, origFilePath]); return; diff --git a/examples/pxScene2d/src/rcvrcore/utils/FileUtils.js b/examples/pxScene2d/src/rcvrcore/utils/FileUtils.js index 3c309d46f4..74b6a13e72 100644 --- a/examples/pxScene2d/src/rcvrcore/utils/FileUtils.js +++ b/examples/pxScene2d/src/rcvrcore/utils/FileUtils.js @@ -18,6 +18,9 @@ limitations under the License. "use strict"; +var isDuk=(typeof Duktape != "undefined")?true:false; +var isV8=(typeof _isV8 != "undefined")?true:false; + var fs = require("fs"); var http = require("http"); var https = require("https"); @@ -70,17 +73,15 @@ function loadFile(fileUri) { fileUri = fileUri.substring(1); } } - var infile = fs.createReadStream(fileUri); - infile.on('data', function (data) { - code += data; - }); - infile.on('end', function () { - log.message(3, "Got file[" + fileUri + "] from file system"); - resolve(code); - }); - infile.on('error', function (err) { - log.error("FAILED to read file[" + fileUri + "] from file system"); - reject(err); + + fs.readFile(fileUri, function (err, data) { + if (err) { + log.error("FAILED to read file[" + fileUri + "] from file system (error=" + err + ")"); + reject(err); + } else { + log.message(3, "Got file[" + fileUri + "] from file system"); + resolve(data); + } }); } }); diff --git a/examples/pxScene2d/src/v8_modules/http.js b/examples/pxScene2d/src/v8_modules/http.js index 26fe7db604..5a4171ee63 100644 --- a/examples/pxScene2d/src/v8_modules/http.js +++ b/examples/pxScene2d/src/v8_modules/http.js @@ -24,4 +24,5 @@ function get(url, cb) { module.exports = { 'get': get, + 'request': get, } diff --git a/examples/pxScene2d/src/v8_modules/https.js b/examples/pxScene2d/src/v8_modules/https.js index 26fe7db604..5a4171ee63 100644 --- a/examples/pxScene2d/src/v8_modules/https.js +++ b/examples/pxScene2d/src/v8_modules/https.js @@ -24,4 +24,5 @@ function get(url, cb) { module.exports = { 'get': get, + 'request': get, } diff --git a/examples/pxScene2d/src/v8_modules/net.js b/examples/pxScene2d/src/v8_modules/net.js new file mode 100644 index 0000000000..1084611610 --- /dev/null +++ b/examples/pxScene2d/src/v8_modules/net.js @@ -0,0 +1,28 @@ +/* + +pxCore Copyright 2005-2018 John Robinson + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/ + +"use strict"; + +module.exports = { + 'connect': function () {}, + 'createConnection': function () { }, + 'Socket': function () { }, + 'isIP': function () { return 1; }, + 'isIPv4': function () { return 1; }, + 'isIPv6': function () { return 1; }, +} diff --git a/src/rtScriptV8Node/rtScriptV8.cpp b/src/rtScriptV8Node/rtScriptV8.cpp index 10027adb44..574a9d088d 100644 --- a/src/rtScriptV8Node/rtScriptV8.cpp +++ b/src/rtScriptV8Node/rtScriptV8.cpp @@ -1041,10 +1041,11 @@ namespace rtScriptV8NodeUtils return; } - Local arrBuf = ArrayBuffer::New(isolate, ptr, req.result, ArrayBufferCreationMode::kInternalized); + Local ret = String::NewFromOneByte(isolate, (const uint8_t *)ptr, v8::NewStringType::kNormal, req.result).ToLocalChecked(); + free(ptr); - args.GetReturnValue().Set(arrBuf); + args.GetReturnValue().Set(ret); } static void uvFsClose(const v8::FunctionCallbackInfo& args) @@ -1360,6 +1361,7 @@ namespace rtScriptV8NodeUtils rtReadOnlyProperty(statusCode, statusCode, int32_t); rtReadOnlyProperty(message, errorMessage, rtString); rtMethod2ArgAndNoReturn("on", addListener, rtString, rtFunctionRef); + rtMethodNoArgAndNoReturn("abort", abort); rtHttpResponse() : mStatusCode(0) { mEmit = new rtEmit(); @@ -1368,6 +1370,7 @@ namespace rtScriptV8NodeUtils rtError statusCode(int32_t& v) const { v = mStatusCode; return RT_OK; } rtError errorMessage(rtString& v) const { v = mErrorMessage; return RT_OK; } rtError addListener(rtString eventName, const rtFunctionRef& f) { mEmit->addListener(eventName, f); return RT_OK; } + rtError abort() const { return RT_OK; } static void onDownloadComplete(rtFileDownloadRequest* downloadRequest); static size_t onDownloadInProgress(void *ptr, size_t size, size_t nmemb, void *userData); @@ -1382,6 +1385,7 @@ namespace rtScriptV8NodeUtils rtDefineProperty(rtHttpResponse, statusCode); rtDefineProperty(rtHttpResponse, message); rtDefineMethod(rtHttpResponse, addListener); + rtDefineMethod(rtHttpResponse, abort); void rtHttpResponse::onDownloadComplete(rtFileDownloadRequest* downloadRequest) { @@ -1405,7 +1409,7 @@ namespace rtScriptV8NodeUtils rtError rtHttpGetBinding(int numArgs, const rtValue* args, rtValue* result, void* context) { - if (numArgs != 2) { + if (numArgs < 1) { return RT_ERROR_INVALID_ARG; } @@ -1429,17 +1433,15 @@ namespace rtScriptV8NodeUtils resourceUrl.append(path.cString()); } - if (args[1].getType() != RT_functionType) { - return RT_ERROR_INVALID_ARG; - } - rtValue ret; rtObjectRef resp(new rtHttpResponse()); - args[1].toFunction().sendReturns(resp, ret); - rtFileDownloadRequest *downloadRequest = new rtFileDownloadRequest(resourceUrl, resp.getPtr(), rtHttpResponse::onDownloadComplete); - downloadRequest->setDownloadProgressCallbackFunction(rtHttpResponse::onDownloadInProgress, resp.getPtr()); - rtFileDownloader::instance()->addToDownloadQueue(downloadRequest); + if (numArgs > 1 && args[1].getType() == RT_functionType) { + args[1].toFunction().sendReturns(resp, ret); + rtFileDownloadRequest *downloadRequest = new rtFileDownloadRequest(resourceUrl, resp.getPtr(), rtHttpResponse::onDownloadComplete); + downloadRequest->setDownloadProgressCallbackFunction(rtHttpResponse::onDownloadInProgress, resp.getPtr()); + rtFileDownloader::instance()->addToDownloadQueue(downloadRequest); + } *result = resp;