first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (realm) {
// Extract the bootstrap source code from the hosting Node version.
var nodeSourceCode = process.binding("natives");
var bootstrapSource = nodeSourceCode["internal/bootstrap_node"];
var bootstrapFilename = "bootstrap_node.js";
if (!bootstrapSource) {
throw new _errors.FatalError("The node-cli mode is only compatible with Node 7.");
}
// We evaluate bootstrap script to get the bootstrap function.
var bootstrapFn = realm.$GlobalEnv.execute(bootstrapSource, bootstrapFilename, "");
if (!(bootstrapFn instanceof _index.FunctionValue) || !bootstrapFn.$Call) {
throw new _errors.FatalError("The node bootstrap script should always yield a function.");
}
return bootstrapFn;
};
var _errors = require("../../errors.js");
var _index = require("../../values/index.js");
//# sourceMappingURL=bootstrap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/intrinsics/node/bootstrap.js"],"names":["realm","nodeSourceCode","process","binding","bootstrapSource","bootstrapFilename","bootstrapFn","$GlobalEnv","execute","$Call"],"mappings":";;;;;;kBAiBe,UAASA,KAAT,EAAsC;AACnD;AACA,MAAIC,iBAAiBC,QAAQC,OAAR,CAAgB,SAAhB,CAArB;AACA,MAAIC,kBAAkBH,eAAe,yBAAf,CAAtB;AACA,MAAII,oBAAoB,mBAAxB;AACA,MAAI,CAACD,eAAL,EAAsB;AACpB,UAAM,uBAAe,mDAAf,CAAN;AACD;;AAED;AACA,MAAIE,cAAcN,MAAMO,UAAN,CAAiBC,OAAjB,CAAyBJ,eAAzB,EAA0CC,iBAA1C,EAA6D,EAA7D,CAAlB;;AAEA,MAAI,EAAEC,2CAAF,KAA2C,CAACA,YAAYG,KAA5D,EAAmE;AACjE,UAAM,uBAAe,2DAAf,CAAN;AACD;;AAED,SAAOH,WAAP;AACD,C;;AAvBD;;AAEA","file":"bootstrap.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport { FatalError } from \"../../errors.js\";\nimport type { Realm } from \"../../realm.js\";\nimport { FunctionValue } from \"../../values/index.js\";\n\ndeclare var process: any;\n\nexport default function(realm: Realm): FunctionValue {\n // Extract the bootstrap source code from the hosting Node version.\n let nodeSourceCode = process.binding(\"natives\");\n let bootstrapSource = nodeSourceCode[\"internal/bootstrap_node\"];\n let bootstrapFilename = \"bootstrap_node.js\";\n if (!bootstrapSource) {\n throw new FatalError(\"The node-cli mode is only compatible with Node 7.\");\n }\n\n // We evaluate bootstrap script to get the bootstrap function.\n let bootstrapFn = realm.$GlobalEnv.execute(bootstrapSource, bootstrapFilename, \"\");\n\n if (!(bootstrapFn instanceof FunctionValue) || !bootstrapFn.$Call) {\n throw new FatalError(\"The node bootstrap script should always yield a function.\");\n }\n\n return bootstrapFn;\n}\n"]}

View File

@@ -0,0 +1,160 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
exports.default = function (realm) {
var nativeBuffer = process.binding("buffer");
var nativeBufferPrototype = require("buffer").Buffer.prototype;
var intrinsicName = 'process.binding("buffer")';
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, intrinsicName);
// Buffer
var setupBufferJS = new _index.NativeFunctionValue(realm, intrinsicName + ".setupBufferJS", "setupBufferJS", 0, function (setupContext, setupArgs) {
(0, _invariant2.default)(setupArgs.length === 2);
(0, _invariant2.default)(setupArgs[0] instanceof _index.ObjectValue);
(0, _invariant2.default)(setupArgs[1] instanceof _index.ObjectValue);
// TODO: Mutate the second argument by setting one of the properties to
// Buffer prototype just like the native implementation does.
var _setupArgs = _slicedToArray(setupArgs, 1),
proto = _setupArgs[0];
var simpleWrapperNames = ["asciiSlice", "base64Slice", "latin1Slice", "hexSlice", "ucs2Slice", "asciiWrite", "base64Write", "latin1Write", "hexWrite", "ucs2Write", "utf8Write"];
var _loop = function _loop(name) {
var wrapper = new _index.NativeFunctionValue(realm, "Buffer.prototype." + name, name, 0, function (context, args) {
throw new _errors.FatalError("TODO: " + name);
});
_singletons.Properties.Set(realm, proto, name, wrapper, true);
};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = simpleWrapperNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
_loop(name);
}
// utf8Slice is used to read source code.
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var utf8Slice = new _index.NativeFunctionValue(realm, "Buffer.prototype.utf8Slice", "utf8Slice", 0, function (context, args) {
(0, _invariant2.default)(context instanceof _index.ObjectValue);
var self = (0, _utils.getNodeBufferFromTypedArray)(realm, context);
var decodedArgs = args.map(function (arg, i) {
return _singletons.To.ToInteger(realm, arg);
});
var utf8String = nativeBufferPrototype.utf8Slice.apply(self, decodedArgs);
return new _index.StringValue(realm, utf8String);
});
_singletons.Properties.Set(realm, proto, "utf8Slice", utf8Slice, true);
// copy has recently moved from the prototype to the instance upstream.
var copy = new _index.NativeFunctionValue(realm, "Buffer.prototype.copy", "copy", 0, function (context, args) {
(0, _invariant2.default)(context instanceof _index.ObjectValue);
var self = (0, _utils.getNodeBufferFromTypedArray)(realm, context);
var decodedArgs = args.map(function (arg, i) {
if (i === 0) {
(0, _invariant2.default)(arg instanceof _index.ObjectValue);
return (0, _utils.getNodeBufferFromTypedArray)(realm, arg);
} else {
return _singletons.To.ToInteger(realm, arg);
}
});
var bytesCopied = nativeBufferPrototype.copy.apply(self, decodedArgs);
return new _index.NumberValue(realm, bytesCopied);
});
_singletons.Properties.Set(realm, proto, "copy", copy, true);
// TODO: Set up more methods on the prototype and bindingObject
return realm.intrinsics.undefined;
});
_singletons.Properties.Set(realm, obj, "setupBufferJS", setupBufferJS, true);
var createFromString = new _index.NativeFunctionValue(realm, intrinsicName + ".createFromString", "createFromString", 0, function (context, args) {
throw new _errors.FatalError("TODO");
});
_singletons.Properties.Set(realm, obj, "createFromString", createFromString, true);
var simpleWrapperNames = ["byteLengthUtf8", "copy", "compare", "compareOffset", "fill", "indexOfBuffer", "indexOfNumber", "indexOfString", "readDoubleBE", "readDoubleLE", "readFloatBE", "readFloatLE", "writeDoubleBE", "writeDoubleLE", "writeFloatBE", "writeFloatLE", "swap16", "swap32", "swap64"];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = simpleWrapperNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var name = _step2.value;
var wrapper = new _index.NativeFunctionValue(realm, intrinsicName + "." + name, name, 0, function (context, args) {
throw new _errors.FatalError("TODO");
});
_singletons.Properties.Set(realm, obj, name, wrapper, true);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
_singletons.Properties.Set(realm, obj, "kMaxLength", new _index.NumberValue(realm, nativeBuffer.kMaxLength), true);
_singletons.Properties.Set(realm, obj, "kStringMaxLength", new _index.NumberValue(realm, nativeBuffer.kStringMaxLength), true);
return obj;
};
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _errors = require("../../errors.js");
var _realm = require("../../realm.js");
var _index = require("../../values/index.js");
var _utils = require("./utils.js");
var _singletons = require("../../singletons.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=buffer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,388 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = function (realm) {
var intrinsicName = 'process.binding("contextify")';
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, intrinsicName);
// Contextify
function runInDebugContextImpl(code) {
// TODO: Make this an abstract result.
throw realm.createErrorThrowCompletion(realm.intrinsics.Error, "The V8 debugger is not available from within Prepack.");
}
function makeContextImpl() {
// TODO: Allow sub-realms to be created and restored.
throw realm.createErrorThrowCompletion(realm.intrinsics.Error, "makeContext is not yet implemented in Prepack.");
}
function isContextImpl() {
// TODO: We don't have a way to create contexts so this is always false.
return realm.intrinsics.false;
}
// ContextifyScript
var ContextifyScriptInternal = function ContextifyScriptInternal(ast) {
_classCallCheck(this, ContextifyScriptInternal);
this.ast = ast;
};
function ContextifyScriptConstructor(context, args, argLength, newTarget) {
if (!newTarget) {
throw realm.createErrorThrowCompletion(realm.intrinsics.Error, "Must call vm.Script as a constructor.");
}
var proto = (0, _index2.Get)(realm, newTarget, "prototype");
if (!(proto instanceof _index.ObjectValue)) {
realm = (0, _index2.GetFunctionRealm)(realm, newTarget);
proto = ContextifyScriptPrototype;
}
(0, _invariant2.default)(args[0] instanceof _index.ConcreteValue);
var code = _singletons.To.ToString(realm, args[0]);
var options = args[1];
var filename = getFilenameArg(options);
var lineOffset = getLineOffsetArg(options);
var columnOffset = getColumnOffsetArg(options);
var displayErrors = getDisplayErrorsArg(options);
var cachedDataBuf = getCachedData(options);
var produceCachedData = getProduceCachedData(options);
var resolvedOptions = {
filename: filename,
lineOffset: lineOffset,
columnOffset: columnOffset,
displayErrors: displayErrors,
cachedDataBuf: undefined, // Not serializable.
produceCachedData: produceCachedData
};
var intrinsicConstructor = "new (" + intrinsicName + ").ContextifyScript(" + JSON.stringify(code) + ", " + JSON.stringify(resolvedOptions) + ")";
var self = new _index.ObjectValue(realm, proto, intrinsicConstructor);
if (cachedDataBuf.length) {
_singletons.Properties.Set(realm, obj, "cachedDataRejected", realm.intrinsics.true, true);
}
if (produceCachedData) {
_singletons.Properties.Set(realm, obj, "cachedDataProduced", realm.intrinsics.false, true);
}
var ast = void 0;
try {
// TODO: Somehow pass columnOffset to Babylon.
ast = (0, _parse2.default)(realm, transform(code, filename), filename, "script", 1 + lineOffset);
} catch (e) {
if (displayErrors && e instanceof _completions.ThrowCompletion) {
decorateErrorStack(e);
}
throw e;
}
// TODO: Pick up source map files and automatically fix up source locations.
self.$InternalSlot = new ContextifyScriptInternal(ast);
return self;
}
var runInDebugContext = new _index.NativeFunctionValue(realm, intrinsicName + ".runInDebugContext", "runInDebugContext", 0, runInDebugContextImpl);
_singletons.Properties.Set(realm, obj, "runInDebugContext", runInDebugContext, true);
var makeContext = new _index.NativeFunctionValue(realm, intrinsicName + ".makeContext", "makeContext", 0, makeContextImpl);
_singletons.Properties.Set(realm, obj, "makeContext", makeContext, true);
var isContext = new _index.NativeFunctionValue(realm, intrinsicName + ".isContext", "isContext", 0, isContextImpl);
_singletons.Properties.Set(realm, obj, "isContext", isContext, true);
var ContextifyScript = new _index.NativeFunctionValue(realm, intrinsicName + ".ContextifyScript", "ContextifyScript", 0, ContextifyScriptConstructor, true);
_singletons.Properties.Set(realm, obj, "ContextifyScript", ContextifyScript, true);
// ContextifyScript.prototype
function runInThisContext(self, args) {
var timeout = getTimeoutArg(args[0]);
var displayErrors = getDisplayErrorsArg(args[0]);
var breakOnSigint = getBreakOnSigintArg(args[0]);
return evalMachine(self, timeout, displayErrors, breakOnSigint);
}
function runInContext(self, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
sandbox = _ref2[0],
options = _ref2[1];
throw realm.createErrorThrowCompletion(realm.intrinsics.Error, "Cannot run in arbitrary contexts within Prepack yet.");
}
function decorateErrorStack(completion) {
var error = completion.value;
if (!(error instanceof _index.ObjectValue)) {
return;
}
var errorData = error.$ErrorData;
if (!errorData) {
return;
}
var errorLocation = errorData.locationData;
if (!errorLocation || errorLocation.stackDecorated) {
return;
}
var stack = (0, _index2.Get)(realm, error, "stack");
if (!(stack instanceof _index.StringValue)) {
return;
}
var lines = errorLocation.sourceCode.split(/\r?\n/);
var line = lines[errorLocation.loc.line - 1] || "";
var arrow = " ".repeat(errorLocation.loc.column) + "^";
var decoratedStack = errorLocation.filename + ":" + errorLocation.loc.line + "\n" + line + "\n" + arrow + "\n" + stack.value;
_singletons.Properties.Set(realm, error, "stack", new _index.StringValue(realm, decoratedStack), false);
errorLocation.stackDecorated = true;
}
function getBreakOnSigintArg(options) {
if (options instanceof _index.UndefinedValue || options instanceof _index.StringValue) {
return false;
}
if (!(options instanceof _index.ObjectValue)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "options must be an object");
}
var value = (0, _index2.Get)(realm, options, "breakOnSigint");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
return value instanceof _index.BooleanValue && value.value;
}
function getTimeoutArg(options) {
if (options instanceof _index.UndefinedValue || options instanceof _index.StringValue) {
return -1;
}
if (!(options instanceof _index.ObjectValue)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "options must be an object");
}
var value = (0, _index2.Get)(realm, options, "timeout");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
if (value instanceof _index.UndefinedValue) {
return -1;
}
var timeout = _singletons.To.ToInteger(realm, value);
if (timeout <= 0) {
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "timeout must be a positive number");
}
return timeout;
}
function getDisplayErrorsArg(options) {
if (options instanceof _index.UndefinedValue || options instanceof _index.StringValue) {
return true;
}
if (!(options instanceof _index.ObjectValue)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "options must be an object");
}
var value = (0, _index2.Get)(realm, options, "displayErrors");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
if (value instanceof _index.UndefinedValue) {
return true;
}
return _singletons.To.ToBoolean(realm, value);
}
function getFilenameArg(options) {
var defaultFilename = "evalmachine.<anonymous>";
if (options instanceof _index.UndefinedValue) {
return defaultFilename;
}
if (options instanceof _index.StringValue) {
return options.value;
}
if (!(options instanceof _index.ObjectValue)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "options must be an object");
}
var value = (0, _index2.Get)(realm, options, "filename");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
if (value instanceof _index.UndefinedValue) {
return defaultFilename;
}
return _singletons.To.ToString(realm, value);
}
function getCachedData(options) {
if (!(options instanceof _index.ObjectValue)) {
return new Uint8Array(0);
}
var value = (0, _index2.Get)(realm, options, "cachedData");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
if (value instanceof _index.UndefinedValue) {
return new Uint8Array(0);
}
if (!value.$ViewedArrayBuffer || !(value.$ViewedArrayBuffer.$ArrayBufferData instanceof Uint8Array)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "options.cachedData must be a Buffer instance");
}
return value.$ViewedArrayBuffer.$ArrayBufferData;
}
function getProduceCachedData(options) {
if (!(options instanceof _index.ObjectValue)) {
return false;
}
var value = (0, _index2.Get)(realm, options, "produceCachedData");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
return value instanceof _index.BooleanValue && value.value;
}
function getLineOffsetArg(options) {
var defaultLineOffset = 0;
if (!(options instanceof _index.ObjectValue)) {
return defaultLineOffset;
}
var value = (0, _index2.Get)(realm, options, "lineOffset");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
return value instanceof _index.UndefinedValue ? defaultLineOffset : _singletons.To.ToInteger(realm, value);
}
function getColumnOffsetArg(options) {
var defaultColumnOffset = 0;
if (!(options instanceof _index.ObjectValue)) {
return defaultColumnOffset;
}
var value = (0, _index2.Get)(realm, options, "columnOffset");
(0, _invariant2.default)(value instanceof _index.ConcreteValue);
return value instanceof _index.UndefinedValue ? defaultColumnOffset : _singletons.To.ToInteger(realm, value);
}
function evalMachine(self, timeout, displayErrors, breakOnSigint) {
if (!(self instanceof _index.ObjectValue) || !(self.$InternalSlot instanceof ContextifyScriptInternal)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.Error, "Script methods can only be called on script instances.");
}
var script = self.$InternalSlot;
var environment = realm.$GlobalEnv;
var previousContext = realm.getRunningContext();
previousContext.suspend();
var context = realm.createExecutionContext();
context.lexicalEnvironment = environment;
context.variableEnvironment = environment;
context.realm = realm;
realm.pushContext(context);
var result = void 0;
try {
result = environment.evaluateCompletion(script.ast, false);
} finally {
context.suspend();
realm.popContext(context);
(0, _invariant2.default)(context.lexicalEnvironment === realm.$GlobalEnv);
realm.onDestroyScope(context.lexicalEnvironment);
}
(0, _invariant2.default)(realm.getRunningContext() === previousContext);
previousContext.resume();
if (result instanceof _index.EmptyValue) {
return realm.intrinsics.undefined;
} else if (result instanceof _index.Value) {
return result;
} else {
(0, _invariant2.default)(result instanceof _completions.AbruptCompletion);
if (displayErrors) {
decorateErrorStack(result);
}
throw result;
}
}
var ContextifyScriptPrototype = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, intrinsicName + ".ContextifyScript.prototype");
ContextifyScriptPrototype.defineNativeMethod("runInContext", 2, runInContext);
ContextifyScriptPrototype.defineNativeMethod("runInThisContext", 1, runInThisContext);
_singletons.Properties.DefinePropertyOrThrow(realm, ContextifyScript, "prototype", {
value: ContextifyScriptPrototype,
writable: true,
enumerable: false,
configurable: false
});
_singletons.Properties.DefinePropertyOrThrow(realm, ContextifyScriptPrototype, "constructor", {
value: ContextifyScript,
writable: true,
enumerable: false,
configurable: true
});
return obj;
};
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _realm = require("../../realm.js");
var _completions = require("../../completions.js");
var _index = require("../../values/index.js");
var _index2 = require("../../methods/index.js");
var _singletons = require("../../singletons.js");
var _parse = require("../../utils/parse.js");
var _parse2 = _interopRequireDefault(_parse);
var _babelCore = require("babel-core");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// TODO: This creates a strong dependency on babel and its transforms even
// outside of devDependencies which is unfortunate. Get rid of this once classes
// and destructuring is fully implemented.
// Hook for transpiling
function transform(code, filename) {
var patchedCode = code.replace(
// Work around the fact that Babel classes can't extend natives.
/class FastBuffer extends Uint8Array {\s+constructor\(arg1, arg2, arg3\) {\s+super\(arg1, arg2, arg3\);\s+}\s+}/g, "function FastBuffer(arg1, arg2, arg3) {\n" + " var self = new Uint8Array(arg1, arg2, arg3);\n" + " Object.setPrototypeOf(self, FastBuffer.prototype);\n" + " return self;\n" + "}; Object.setPrototypeOf(FastBuffer, Uint8Array); Object.setPrototypeOf(FastBuffer.prototype, Uint8Array.prototype);");
var transformedCode = (0, _babelCore.transform)(patchedCode, {
plugins: [
// Prepack doesn't support classes or destructuring yet.
"transform-es2015-classes", "transform-es2015-destructuring", "transform-es2015-parameters"],
retainLines: true
});
return transformedCode.code;
}
//# sourceMappingURL=contextify.js.map

File diff suppressed because one or more lines are too long

103
build/node_modules/prepack/lib/intrinsics/node/fs.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (realm) {
var intrinsicName = 'process.binding("fs")';
var nativeFS = process.binding("fs");
// fs
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, intrinsicName);
obj.defineNativeMethod("FSInitialize", 0, function (context, args) {
// TODO: Implement the native implementation.
return realm.intrinsics.undefined;
});
obj.defineNativeMethod("internalModuleStat", 0, function (context, args) {
var fileName = _singletons.To.ToString(realm, args[0]);
return new _index.NumberValue(realm, nativeFS.internalModuleStat(fileName));
});
obj.defineNativeMethod("lstat", 0, function (context, args) {
var path = _singletons.To.ToString(realm, args[0]);
(0, _invariant2.default)(args[1] instanceof _index.ObjectValue);
var buffer = (0, _utils.getNodeBufferFromTypedArray)(realm, args[1]);
var float64buffer = new Float64Array(buffer.buffer);
nativeFS.lstat(path, float64buffer);
return args[1];
});
obj.defineNativeMethod("fstat", 0, function (context, args) {
var fd = _singletons.To.ToNumber(realm, args[0]);
(0, _invariant2.default)(args[1] instanceof _index.ObjectValue);
var buffer = (0, _utils.getNodeBufferFromTypedArray)(realm, args[1]);
var float64buffer = new Float64Array(buffer.buffer);
nativeFS.fstat(fd, float64buffer);
return args[1];
});
obj.defineNativeMethod("open", 0, function (context, args) {
var path = _singletons.To.ToString(realm, args[0]);
var flags = _singletons.To.ToNumber(realm, args[1]);
var mode = _singletons.To.ToNumber(realm, args[2]);
var fd = nativeFS.open(path, flags, mode);
return new _index.NumberValue(realm, fd);
});
obj.defineNativeMethod("close", 0, function (context, args) {
var fd = _singletons.To.ToNumber(realm, args[0]);
nativeFS.close(fd);
return realm.intrinsics.undefined;
});
obj.defineNativeMethod("read", 0, function (context, args) {
var fd = _singletons.To.ToNumber(realm, args[0]);
(0, _invariant2.default)(args[1] instanceof _index.ObjectValue);
var buffer = (0, _utils.getNodeBufferFromTypedArray)(realm, args[1]);
var offset = _singletons.To.ToNumber(realm, args[2]);
var length = _singletons.To.ToNumber(realm, args[3]);
var position = args[4] === realm.intrinsics.undefined ? undefined : _singletons.To.ToNumber(realm, args[4]);
var bytesRead = nativeFS.read(fd, buffer, offset, length, position);
return new _index.NumberValue(realm, bytesRead);
});
obj.defineNativeMethod("internalModuleReadFile", 0, function (context, args) {
var path = _singletons.To.ToString(realm, args[0]);
var result = nativeFS.internalModuleReadFile(path);
if (result === undefined) {
return realm.intrinsics.undefined;
}
return new _index.StringValue(realm, result);
});
var FSReqWrapTemplateSrc = intrinsicName + ".FSReqWrap";
var FSReqWrapTemplate = (0, _builder2.default)(FSReqWrapTemplateSrc);
var val = _index.AbstractValue.createFromTemplate(realm, FSReqWrapTemplate, _index.ObjectValue, [], FSReqWrapTemplateSrc);
val.values = new _index2.ValuesDomain(new Set([new _index.ObjectValue(realm)]));
val.intrinsicName = FSReqWrapTemplateSrc;
_singletons.Properties.DefinePropertyOrThrow(realm, obj, "FSReqWrap", {
value: val,
writable: true,
configurable: true,
enumerable: true
});
// TODO: Implement more of the native methods here. Ideally all of them should
// just be automatically proxied.
return obj;
};
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _index = require("../../values/index.js");
var _index2 = require("../../domains/index.js");
var _builder = require("../../utils/builder.js");
var _builder2 = _interopRequireDefault(_builder);
var _utils = require("./utils.js");
var _singletons = require("../../singletons.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=fs.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,615 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
exports.default = function (realm, processArgv) {
if (!realm.useAbstractInterpretation) {
(0, _invariant2.default)(false, "Realm is not enabled for Abstract Interpretation");
}
// TODO: This causes a dependency on the native `process` which doesn't
// exist in all environments such as the webpack version.
// Constant bindings
// TODO: Implement icu module so that we can let hasIntl be true.
var configOverride = _extends({}, process.binding("config"), { hasIntl: false });
// By the time we run the host has already deleted natives.config so we have
// to restore it.
var nativeOverride = _extends({}, process.binding("natives"), { config: reverseConfigJSON(process.config) });
var config = (0, _utils.createDeepIntrinsic)(realm, configOverride, 'process.binding("config")');
var constants = (0, _utils.createDeepIntrinsic)(realm, process.binding("constants"), 'process.binding("constants")');
var natives = (0, _utils.createDeepIntrinsic)(realm, nativeOverride, 'process.binding("natives")');
// Built-in native bindings
var contextify = (0, _contextify2.default)(realm);
var fs = (0, _fs2.default)(realm);
var fsEvent = initializeFSEvent(realm);
var url = initializeURL(realm);
var timerWrap = initializeTimerWrap(realm);
var ttyWrap = initializeTTYWrap(realm);
var signalWrap = initializeSignalWrap(realm);
var streamWrap = initializeStreamWrap(realm);
var caresWrap = createAbstractValue(realm, _index.ObjectValue, 'process.binding("cares_wrap")');
var tcpWrap = createAbstractValue(realm, _index.ObjectValue, 'process.binding("tcp_wrap")');
tcpWrap.makeSimple();
var pipeWrap = createAbstractValue(realm, _index.ObjectValue, 'process.binding("pipe_wrap")');
pipeWrap.makeSimple();
var uv = createAbstractValue(realm, _index.ObjectValue, 'process.binding("uv")');
var buffer = (0, _buffer2.default)(realm);
var util = initializeUtil(realm);
var os = createAbstractValue(realm, _index.ObjectValue, 'process.binding("os")');
os.makeSimple();
// List of loaded native modules
var moduleLoadList = createIntrinsicArrayValue(realm, "process.moduleLoadList");
// The process object
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process");
obj.defineNativeMethod("binding", 1, function (context, args) {
var arg0 = args.length < 1 ? realm.intrinsics.undefined : args[0];
var module = _singletons.To.ToString(realm, arg0);
// TODO: Add the module to the moduleLoadList but don't track that
// as a side-effect.
switch (module) {
// Constants
case "config":
return config;
case "constants":
return constants;
case "natives":
return natives;
// Built-in bindings
case "contextify":
return contextify;
case "fs":
return fs;
case "fs_event_wrap":
return fsEvent;
case "url":
return url;
case "uv":
return uv;
case "buffer":
return buffer;
case "util":
return util;
case "os":
return os;
case "timer_wrap":
return timerWrap;
case "tty_wrap":
return ttyWrap;
case "cares_wrap":
return caresWrap;
case "tcp_wrap":
return tcpWrap;
case "pipe_wrap":
return pipeWrap;
case "stream_wrap":
return streamWrap;
case "signal_wrap":
return signalWrap;
default:
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "No such module: " + module);
}
});
(0, _utils.copyProperty)(realm, process, obj, "moduleLoadList", moduleLoadList);
// Constants on the process
var constantNames = ["version", "versions", "_promiseRejectEvent", "arch", "platform", "release", "features", "_needImmediateCallback"];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = constantNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
var value = (0, _utils.createDeepIntrinsic)(realm, process[name], "process." + name);
(0, _utils.copyProperty)(realm, process, obj, name, value);
}
// process._events is a mutable object with null prototype.
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _events = new _index.ObjectValue(realm, realm.intrinsics.null, "process._events");
(0, _utils.copyProperty)(realm, process, obj, "_events", _events);
// TODO: When abstract numbers in string templates is implemented, turn this
// back into an abstract value.
// let pid = createAbstractValue(realm, NumberValue, "process.pid");
var pid = new _index.NumberValue(realm, 0, "process.pid");
(0, _utils.copyProperty)(realm, process, obj, "pid", pid);
var debugPort = createAbstractValue(realm, _index.NumberValue, "process.debugPort");
(0, _utils.copyProperty)(realm, process, obj, "debugPort", debugPort);
var title = createAbstractValue(realm, _index.StringValue, "process.title");
(0, _utils.copyProperty)(realm, process, obj, "title", title);
// process.execArgv should probably be passed as an argument to the compile
// step rather than letting arbitrary options be passed to the program.
// For now I'll just hard code it as empty array.
// TODO: Allow execArgv to be passed as a compiler option.
var execArgv = createIntrinsicArrayValue(realm, "process.execArgv");
(0, _utils.copyProperty)(realm, process, obj, "execArgv", execArgv);
var cwd = new _index.NativeFunctionValue(realm, "process.cwd", "cwd", 0, function (context, args) {
return new _index.StringValue(realm, process.cwd(), "process.cwd()");
});
(0, _utils.copyProperty)(realm, process, obj, "cwd", cwd);
// These properties all depend on options being defined in "execArgv" but
// since we hard coded it, none of this will be added.
// "_eval" : string
// "_print_eval" : boolean
// "_syntax_check_only" : boolean
// "_forceRepl" : boolean
// "noDeprecation" : boolean
// "noProcessWarnings" : boolean
// "traceProcessWarnings" : boolean
// "throwDeprecation" : boolean
// "_noBrowserGlobals" : boolean
// "profProcess" : boolean
// "traceDeprecation" : boolean
// "_debugWaitConnect" : boolean
// "_preload_modules" gets looped over so it needs to be known but typically
// we don't need to do this so we can just leave it not defined.
// Side-effectful Methods
var methodNames = ["_startProfilerIdleNotifier", "_stopProfilerIdleNotifier", "_getActiveRequests", "_getActiveHandles", "reallyExit", "abort", "chdir", "umask",
// Start Posix only
"getuid", "geteuid", "setuid", "seteuid", "setgid", "setegid", "getgid", "getegid", "getgroups", "setgroups", "initgroups",
// End Posix only
"_kill", "_debugProcess", "_debugPause", "_debugEnd", "hrtime", "cpuUsage", "dlopen", "uptime", "memoryUsage", "_linkedBinding", "_setupNextTick", "_setupPromises", "_setupDomainUse"];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = methodNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _name = _step2.value;
var abstractMethod = createAbstractValue(realm, _index.FunctionValue, "process." + _name);
(0, _utils.copyProperty)(realm, process, obj, _name, abstractMethod);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var argv0 = new _index.StringValue(realm, process.argv0, "process.argv0");
_singletons.Properties.DefinePropertyOrThrow(realm, obj, "argv0", {
value: argv0,
writable: false,
configurable: true,
enumerable: true
});
var argv = createAbstractValue(realm, _index.ObjectValue, "process.argv");
_singletons.Properties.DefinePropertyOrThrow(realm, argv, "0", {
value: argv0,
writable: true,
configurable: true,
enumerable: true
});
_singletons.Properties.DefinePropertyOrThrow(realm, argv, "1", {
value: new _index.StringValue(realm, processArgv[1]),
writable: true,
configurable: true,
enumerable: true
});
_singletons.Properties.DefinePropertyOrThrow(realm, argv, "indexOf", {
value: new _index.NativeFunctionValue(realm, "process.argv.indexOf", "indexOf", 0, function (context, args) {
return realm.intrinsics.false;
}),
writable: true,
configurable: true,
enumerable: true
});
argv.makeSimple();
(0, _utils.copyProperty)(realm, process, obj, "argv", argv);
var execPath = new _index.StringValue(realm, process.execPath, "process.execPath");
(0, _utils.copyProperty)(realm, process, obj, "execPath", execPath);
var env = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.env");
// TODO: This abstract value doesn't work with a conditional for some reason.
_singletons.Properties.DefinePropertyOrThrow(realm, env, "NODE_NO_WARNINGS", {
value: new _index.StringValue(realm, "0", "process.env.NODE_NO_WARNINGS"),
writable: true,
configurable: true,
enumerable: true
});
// Uncomment this to debug the module resolution system.
// DefinePropertyOrThrow(realm, env, "NODE_DEBUG", {
// value: new StringValue(
// realm, "module", "process.env.NODE_DEBUG"
// ),
// writable: true,
// configurable: true,
// enumerable: true,
// });
env.makeSimple();
(0, _utils.copyProperty)(realm, process, obj, "env", env);
// This method just gets passed a value from the initialization code and
// then deletes itself.
// TODO: The generated code needs to either always invoke this (make it
// abstract) or, if we assume it has been done, it doesn't need to delete it.
obj.defineNativeMethod("_setupProcessObject", 1, function (self, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
pushValueToArray = _ref2[0];
_singletons.Properties.OrdinaryDelete(realm, obj, "_setupProcessObject");
return realm.intrinsics.undefined;
});
// This method injects a generic global promise reject callback. In real
// environment we'd want to call this at rejections but we can safely skip it.
obj.defineNativeMethod("_setupPromises", 1, function (self, _ref3) {
var _ref4 = _slicedToArray(_ref3, 1),
promiseRejectCallback = _ref4[0];
_singletons.Properties.OrdinaryDelete(realm, obj, "_setupPromises");
return realm.intrinsics.undefined;
});
// TODO: Support Promises. Set up a micro task runner and invoke the
// tickCallback as needed.
obj.defineNativeMethod("_setupNextTick", 1, function (self, _ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
tickCallback = _ref6[0],
runMicrotasks = _ref6[1];
_singletons.Properties.OrdinaryDelete(realm, obj, "_setupNextTick");
var runMicrotasksCallback = new _index.NativeFunctionValue(realm, "(function() { throw new Error('TODO runMicrotasks not reachable') })", "runMicrotasks", 0, function (context, args) {
// TODO: Implement Promises and micro tasks.
return realm.intrinsics.undefined;
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, runMicrotasks, "runMicrotasks", {
value: runMicrotasksCallback,
writable: true,
enumerable: true,
configurable: true
});
var tickInfo = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "(function() { throw new Error('TODO tickInfo is not reachable in the host environment') })");
_singletons.Properties.OrdinaryDefineOwnProperty(realm, tickInfo, "0", {
value: realm.intrinsics.zero,
writable: true,
enumerable: true,
configurable: true
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, tickInfo, "1", {
value: realm.intrinsics.zero,
writable: true,
enumerable: true,
configurable: true
});
return tickInfo;
});
return obj;
};
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _index = require("../../values/index.js");
var _index2 = require("../../methods/index.js");
var _index3 = require("../../domains/index.js");
var _singletons = require("../../singletons.js");
var _builder = require("../../utils/builder.js");
var _builder2 = _interopRequireDefault(_builder);
var _buffer = require("./buffer.js");
var _buffer2 = _interopRequireDefault(_buffer);
var _contextify = require("./contextify.js");
var _contextify2 = _interopRequireDefault(_contextify);
var _fs = require("./fs.js");
var _fs2 = _interopRequireDefault(_fs);
var _utils = require("./utils.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function initializeTimerWrap(realm) {
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('timer_wrap')");
var constructor = new _index.NativeFunctionValue(realm, "process.binding('timer_wrap').Timer", "Timer", 0, function (context, args) {
return realm.intrinsics.undefined;
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, obj, "Timer", {
value: constructor,
writable: true,
enumerable: true,
configurable: true
});
// TODO: Implement the rest of this protocol as needed.
return obj;
}
function initializeTTYWrap(realm) {
var nativeTTYWrap = process.binding("tty_wrap");
// let nativeTTY = nativeTTYWrap.TTY;
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('tty_wrap')");
var constructor = new _index.NativeFunctionValue(realm, "process.binding('tty_wrap').TTY", "TTY", 0, function (context, args, argCount, NewTarget) {
(0, _invariant2.default)(args[0] instanceof _index.ConcreteValue);
var fd = _singletons.To.ToInteger(realm, args[0]);
(0, _invariant2.default)(args[1] instanceof _index.ConcreteValue);
var value = _singletons.To.ToBoolean(realm, args[1]);
(0, _invariant2.default)(NewTarget, "TTY must be called as a constructor.");
var proto = (0, _index2.Get)(realm, NewTarget, new _index.StringValue(realm, "prototype"));
if (!(proto instanceof _index.ObjectValue)) {
proto = TTYPrototype;
}
// TODO: Store nativeTTY in an internal slot so that it can be used if this
// object gets passed to another native call.
return new _index.ObjectValue(realm, proto, "new (process.binding('tty_wrap').TTY)(" + fd + ", " + value.toString() + ")");
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, obj, "TTY", {
value: constructor,
writable: true,
enumerable: true,
configurable: true
});
var TTYPrototype = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('tty_wrap').TTY.prototype");
TTYPrototype.defineNativeMethod("setBlocking", 0, function (context, args) {
return realm.intrinsics.undefined;
});
TTYPrototype.defineNativeMethod("getWindowSize", 0, function (context, args) {
return realm.intrinsics.undefined;
});
TTYPrototype.defineNativeMethod("writeUtf8String", 0, function (context, args) {
// TODO: Store this as a side-effect. When we do that, we need the first arg
// to be passed along to that side-effect.
// let req = args[0];
var content = args[1];
(0, _invariant2.default)(content instanceof _index.StringValue);
return realm.intrinsics.undefined;
});
_singletons.Properties.DefinePropertyOrThrow(realm, constructor, "prototype", {
value: TTYPrototype,
writable: true,
enumerable: false,
configurable: false
});
obj.defineNativeMethod("guessHandleType", 0, function (context, args) {
var fd = _singletons.To.ToInteger(realm, args[0]);
return new _index.StringValue(realm, nativeTTYWrap.guessHandleType(fd));
// TODO: Make this abstract so that changing the pipe at runtime is
// possible. Currently this causes an introspection error.
// let types = new TypesDomain(StringValue);
// let values = new ValuesDomain(new Set([
// new StringValue(realm, "TCP"),
// new StringValue(realm, "TTY"),
// new StringValue(realm, "UDP"),
// new StringValue(realm, "FILE"),
// new StringValue(realm, "PIPE"),
// new StringValue(realm, "UNKNOWN")
// ]));
// let buildNode = buildExpressionTemplate(
// `(process.binding('tty_wrap').guessHandleType(${fd}))`
// )(this.realm.preludeGenerator);
// return realm.createAbstract(types, values, [], buildNode, undefined, `(process.binding('tty_wrap').guessHandleType(${fd}))`);
});
obj.defineNativeMethod("isTTY", 0, function (context, args) {
var fd = _singletons.To.ToInteger(realm, args[0]);
var isTTYtemplateSrc = "(process.binding('tty_wrap').isTTY(" + fd + "))";
var isTTYtemplate = (0, _builder2.default)(isTTYtemplateSrc);
var val = _index.AbstractValue.createFromTemplate(realm, isTTYtemplate, _index.BooleanValue, [], isTTYtemplateSrc);
val.intrinsicName = isTTYtemplateSrc;
return val;
});
// TODO: Implement the rest of this protocol.
return obj;
}
function initializeSignalWrap(realm) {
// TODO: Implement more of this protocol. When doing so, we'll likely need to
// forward it to the native implementation.
// let nativeSignalWrap = process.binding("signal_wrap");
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('signal_wrap')");
var constructor = new _index.NativeFunctionValue(realm, "process.binding('signal_wrap').Signal", "Signal", 0, function (context, args) {
return realm.intrinsics.undefined;
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, obj, "Signal", {
value: constructor,
writable: true,
enumerable: true,
configurable: true
});
var SignalPrototype = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('signal_wrap').Signal.prototype");
SignalPrototype.defineNativeMethod("unref", 0, function (context, args) {
// TODO: Track the side-effect of this.
return realm.intrinsics.undefined;
});
SignalPrototype.defineNativeMethod("start", 0, function (context, args) {
// TODO: Track the side-effect of this.
return realm.intrinsics.undefined;
});
SignalPrototype.defineNativeMethod("close", 0, function (context, args) {
// TODO: Track the side-effect of this.
return realm.intrinsics.undefined;
});
_singletons.Properties.DefinePropertyOrThrow(realm, constructor, "prototype", {
value: SignalPrototype,
writable: true,
enumerable: false,
configurable: false
});
// TODO
return obj;
}
function initializeStreamWrap(realm) {
// let nativeStreamWrap = process.binding("stream_wrap");
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('stream_wrap')");
var constructor = new _index.NativeFunctionValue(realm, "process.binding('stream_wrap').WriteWrap", "WriteWrap", 0, function (context, args) {
return realm.intrinsics.undefined;
});
_singletons.Properties.OrdinaryDefineOwnProperty(realm, obj, "WriteWrap", {
value: constructor,
writable: true,
enumerable: true,
configurable: true
});
var WriteWrapPrototype = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('stream_wrap').WriteWrap.prototype");
WriteWrapPrototype.defineNativeMethod("unref", 0, function (context, args) {
// TODO: Track the side-effect of this.
return realm.intrinsics.undefined;
});
_singletons.Properties.DefinePropertyOrThrow(realm, constructor, "prototype", {
value: WriteWrapPrototype,
writable: true,
enumerable: false,
configurable: false
});
var ShutdownWrap = createAbstractValue(realm, _index.FunctionValue, "process.binding('stream_wrap').ShutdownWrap");
_singletons.Properties.DefinePropertyOrThrow(realm, obj, "ShutdownWrap", {
value: ShutdownWrap,
writable: true,
configurable: true,
enumerable: true
});
// TODO
return obj;
}
function initializeFSEvent(realm) {
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('fs_event_wrap')");
var FSEvent = createAbstractValue(realm, _index.FunctionValue, "process.binding('fs_event_wrap').FSEvent");
_singletons.Properties.DefinePropertyOrThrow(realm, obj, "FSEvent", {
value: FSEvent,
writable: true,
configurable: true,
enumerable: true
});
// TODO
return obj;
}
function initializeURL(realm) {
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype);
// TODO
return obj;
}
function initializeUtil(realm) {
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, 'process.binding("util")');
obj.defineNativeMethod("isUint8Array", 0, function (context, args) {
var arr = args[0];
if (arr instanceof _index.ObjectValue && arr.$TypedArrayName === "Uint8Array") {
return realm.intrinsics.true;
}
return realm.intrinsics.false;
});
(0, _utils.copyProperty)(realm, process.binding("util"), obj, "pushValToArrayMax", new _index.NumberValue(realm, process.binding("util").pushValToArrayMax, 'process.binding("util").pushValToArrayMax'));
// TODO
return obj;
}
function createAbstractValue(realm, type, intrinsicName) {
var template = (0, _builder2.default)(intrinsicName);
var val = _index.AbstractValue.createFromTemplate(realm, template, _index.ObjectValue, [], intrinsicName);
val.values = new _index3.ValuesDomain(new Set([new _index.ObjectValue(realm)]));
val.intrinsicName = intrinsicName;
return val;
}
function createIntrinsicArrayValue(realm, intrinsicName) {
// Like ArrayCreate but accepts an intrinsic name.
var obj = new _index.ArrayValue(realm, intrinsicName);
obj.setExtensible(true);
_singletons.Properties.OrdinaryDefineOwnProperty(realm, obj, "length", {
value: realm.intrinsics.zero,
writable: true,
enumerable: false,
configurable: false
});
return obj;
}
function reverseConfigJSON(config) {
// Hack to restore the gyp config format
var json = JSON.stringify(process.config).replace(/"/g, "'");
return "\n" + json;
}
//# sourceMappingURL=process.js.map

File diff suppressed because one or more lines are too long

123
build/node_modules/prepack/lib/intrinsics/node/utils.js generated vendored Normal file
View File

@@ -0,0 +1,123 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
exports.getNodeBufferFromTypedArray = getNodeBufferFromTypedArray;
exports.createDeepIntrinsic = createDeepIntrinsic;
exports.copyProperty = copyProperty;
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _errors = require("../../errors.js");
var _index = require("../../values/index.js");
var _singletons = require("../../singletons.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getNodeBufferFromTypedArray(realm, value) {
var buffer = value.$ViewedArrayBuffer;
(0, _invariant2.default)(buffer instanceof _index.ObjectValue && buffer.$ArrayBufferData);
return buffer.$ArrayBufferData;
}
// Takes a value from the host realm and create it into a Prepack Realm.
// TODO: Move this to a bigger general purpose proxy between the environments.
// See issue #644 for more details.
function createDeepIntrinsic(realm, value, intrinsicName) {
switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
case "undefined":
return realm.intrinsics.undefined;
case "boolean":
return new _index.BooleanValue(realm, value, intrinsicName);
case "number":
return new _index.NumberValue(realm, value, intrinsicName);
case "string":
return new _index.StringValue(realm, value, intrinsicName);
// $FlowFixMe flow doesn't understand symbols.
case "symbol":
throw new _errors.FatalError("Symbol cannot be safely cloned.");
case "function":
throw new _errors.FatalError("Functions could be supported but are not yet.");
case "object":
{
if (value === null) {
return realm.intrinsics.null;
}
if (Array.isArray(value)) {
throw new _errors.FatalError("Arrays are not supported yet.");
}
var prototype = Object.getPrototypeOf(value);
if (prototype !== Object.prototype) {
throw new _errors.FatalError("Only simple objects are supported for now. Got: " + (typeof prototype.constructor === "function" && prototype.constructor.name || Object.prototype.toString.call(prototype)));
}
var obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype, intrinsicName // We use the intrinsic name for Objects to preserve their referential equality
);
var names = Object.getOwnPropertyNames(value);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
// We intentionally invoke the getter on value[name] which resolves any
// lazy getters.
var newValue = createDeepIntrinsic(realm, value[name], intrinsicName + "." + name);
copyProperty(realm, value, obj, name, newValue);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return obj;
}
default:
(0, _invariant2.default)(false);
}
}
// Define a value with the same descriptor settings as the original object.
function copyProperty(realm, originalObject, realmObject, name, value) {
var desc = Object.getOwnPropertyDescriptor(originalObject, name);
if (!desc) {
return;
}
if (desc.get || desc.set) {
throw new _errors.FatalError("Getter/setters are not supported because functions are not supported yet.");
}
var newDesc = {
value: value,
writable: !!desc.writable,
configurable: !!desc.configurable,
enumerable: !!desc.enumerable
};
_singletons.Properties.DefinePropertyOrThrow(realm, realmObject, name, newDesc);
}
//# sourceMappingURL=utils.js.map

File diff suppressed because one or more lines are too long