UNPKG

2.46 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = Object.setPrototypeOf ||
3 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5 return function (d, b) {
6 extendStatics(d, b);
7 function __() { this.constructor = d; }
8 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9 };
10})();
11// ビルド時はnode_modules下のakashic-engineモジュールのgを参照しているが、実際に利用するgはjs下のengineFilesV*_*_*.jsのものなので、本来なら実行時に参照するgを動的に決定できるようにすべき
12var SandboxScriptAsset = /** @class */ (function (_super) {
13 __extends(SandboxScriptAsset, _super);
14 function SandboxScriptAsset(id, path) {
15 var _this = _super.call(this, id, path) || this;
16 // いきなり読んじゃう
17 var heads = document.getElementsByTagName("head");
18 var container = (heads.length === 0) ? document.body : heads[0];
19 var script = document.createElement("script");
20 script.onload = function () {
21 _this.script = script.text; // TODO: とれない・・
22 _this.loading = false;
23 };
24 script.onerror = function () {
25 _this.loading = false;
26 };
27 _this.script = undefined;
28 _this.loading = true;
29 // TODO: pathに?が入っていたりするとダメなやつ
30 script.src = _this.path + "?id=" + encodeURIComponent(_this.id);
31 container.appendChild(script);
32 return _this;
33 }
34 SandboxScriptAsset.prototype._load = function (loader) {
35 var _this = this;
36 var waitLoader = function () {
37 if (_this.loading) {
38 setTimeout(waitLoader, 100);
39 return;
40 }
41 if (_this.script !== undefined) {
42 loader._onAssetLoad(_this);
43 }
44 else {
45 loader._onAssetError(_this, g.ExceptionFactory.createAssetLoadError("can not load script"));
46 }
47 };
48 setTimeout(waitLoader, this.loading ? 100 : 0);
49 };
50 SandboxScriptAsset.prototype.execute = function (execEnv) {
51 window.gScriptContainer[this.id](execEnv);
52 return execEnv.module.exports;
53 };
54 return SandboxScriptAsset;
55}(g.ScriptAsset));