| 1 |
"use strict"; |
| 2 |
|
| 3 |
var ensureObject = require("type/object/ensure") |
| 4 |
, toShortString = require("type/lib/to-short-string") |
| 5 |
, esEnvType = require("./lib/es-env-type") |
| 6 |
, uniGlobal = require("./lib/uni-global"); |
| 7 |
|
| 8 |
module.exports = function (realmGlobal) { |
| 9 |
ensureObject(realmGlobal, { name: "realmGlobal" }); |
| 10 |
if (typeof realmGlobal.EvalError !== "function") { |
| 11 |
throw new TypeError("Expected a realm global recieved: " + toShortString(realmGlobal)); |
| 12 |
} |
| 13 |
|
| 14 |
switch (esEnvType) { |
| 15 |
case "3": |
| 16 |
if (realmGlobal.EvalError.$ug202109) { |
| 17 |
if (realmGlobal.EvalError.$ug202109 === uniGlobal) return; |
| 18 |
throw new Error("Cannot adapt realm, as it already has uni-global defined"); |
| 19 |
} |
| 20 |
realmGlobal.EvalError.$ug202109 = uniGlobal; |
| 21 |
return; |
| 22 |
case "5": |
| 23 |
if (realmGlobal.EvalError.$uniGlobal202109) { |
| 24 |
if (realmGlobal.EvalError.$uniGlobal202109 === uniGlobal) return; |
| 25 |
throw new Error("Cannot adapt realm, as it already has uni-global defined"); |
| 26 |
} |
| 27 |
Object.defineProperty(realmGlobal.EvalError, "$uniGlobal202109", { value: uniGlobal }); |
| 28 |
return; |
| 29 |
case "2015+": |
| 30 |
var uniGlobalSymbol = Symbol["for"]("$uniGlobal202109"); |
| 31 |
if (realmGlobal.EvalError[uniGlobalSymbol]) { |
| 32 |
if (realmGlobal.EvalError[uniGlobalSymbol] === uniGlobal) return; |
| 33 |
throw new Error("Cannot adapt realm, as it already has uni-global defined"); |
| 34 |
} |
| 35 |
Object.defineProperty(realmGlobal.EvalError, uniGlobalSymbol, { value: uniGlobal }); |
| 36 |
return; |
| 37 |
default: |
| 38 |
throw new Error("Unrecognized environment type: " + esEnvType); |
| 39 |
} |
| 40 |
}; |