Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pxScene2d/src/rcvrcore/AppSceneContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions examples/pxScene2d/src/rcvrcore/utils/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
});
}
});
Expand Down
1 change: 1 addition & 0 deletions examples/pxScene2d/src/v8_modules/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ function get(url, cb) {

module.exports = {
'get': get,
'request': get,
}
1 change: 1 addition & 0 deletions examples/pxScene2d/src/v8_modules/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ function get(url, cb) {

module.exports = {
'get': get,
'request': get,
}
28 changes: 28 additions & 0 deletions examples/pxScene2d/src/v8_modules/net.js
Original file line number Diff line number Diff line change
@@ -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; },
}
24 changes: 13 additions & 11 deletions src/rtScriptV8Node/rtScriptV8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,11 @@ namespace rtScriptV8NodeUtils
return;
}

Local<ArrayBuffer> arrBuf = ArrayBuffer::New(isolate, ptr, req.result, ArrayBufferCreationMode::kInternalized);
Local<String> 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<v8::Value>& args)
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -1382,6 +1385,7 @@ namespace rtScriptV8NodeUtils
rtDefineProperty(rtHttpResponse, statusCode);
rtDefineProperty(rtHttpResponse, message);
rtDefineMethod(rtHttpResponse, addListener);
rtDefineMethod(rtHttpResponse, abort);

void rtHttpResponse::onDownloadComplete(rtFileDownloadRequest* downloadRequest)
{
Expand All @@ -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;
}

Expand All @@ -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;

Expand Down