UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

55 lines (47 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = convert; var _errors = require("../errors.js"); var _index = require("../values/index.js"); var _singletons = require("../singletons.js"); /** * 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. */ function convert(realm, val) { if (typeof val === "number") { return new _index.NumberValue(realm, val); } else if (typeof val === "string") { return new _index.StringValue(realm, val); } else if (val === null) { return realm.intrinsics.null; } else if (val === undefined) { return realm.intrinsics.undefined; } else if (val === true) { return realm.intrinsics.true; } else if (val === false) { return realm.intrinsics.false; } else if (Array.isArray(val)) { return _singletons.Create.CreateArrayFromList(realm, val.map(item => convert(realm, item))); } else if (typeof val === "object") { let obj = new _index.ObjectValue(realm, realm.intrinsics.ObjectPrototype); for (let key in val) { obj.$DefineOwnProperty(key, { enumerable: true, writable: true, configurable: true, value: convert(realm, val[key]) }); } return obj; } else { throw new _errors.FatalError("need to convert value of type " + typeof val); } } //# sourceMappingURL=native-to-interp.js.map