(newNode: WorkerNode, referenceNode: Node | null)
| 47 | set href(_: any) {} |
| 48 | |
| 49 | insertBefore(newNode: WorkerNode, referenceNode: Node | null) { |
| 50 | // ensure the node being added to the window's document |
| 51 | // is given the same winId as the window it's being added to |
| 52 | const winId = (newNode[WinIdKey] = this[WinIdKey]); |
| 53 | const instanceId = newNode[InstanceIdKey]; |
| 54 | const nodeName = newNode[InstanceDataKey]; |
| 55 | const isScript = nodeName === NodeName.Script; |
| 56 | const isIFrame = nodeName === NodeName.IFrame; |
| 57 | |
| 58 | if (isScript) { |
| 59 | const scriptContent = getInstanceStateValue<string>(newNode, StateProp.innerHTML); |
| 60 | const scriptType = getInstanceStateValue<string>(newNode, StateProp.type); |
| 61 | |
| 62 | if (scriptContent) { |
| 63 | if (isScriptJsType(scriptType)) { |
| 64 | // @ts-ignore |
| 65 | const scriptId = newNode.id; |
| 66 | const loadOnMainThread = |
| 67 | scriptId && testIfMustLoadScriptOnMainThread(config, scriptId); |
| 68 | |
| 69 | if (loadOnMainThread) { |
| 70 | setter(newNode, ['type'], 'text/javascript'); |
| 71 | } else { |
| 72 | const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, ''); |
| 73 | const datasetType = errorMsg ? 'pterror' : 'ptid'; |
| 74 | const datasetValue = errorMsg || instanceId; |
| 75 | setter(newNode, ['type'], SCRIPT_TYPE + SCRIPT_TYPE_EXEC); |
| 76 | setter(newNode, ['dataset', datasetType], datasetValue); |
| 77 | } |
| 78 | } |
| 79 | setter(newNode, ['innerHTML'], scriptContent); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | callMethod(this, ['insertBefore'], [newNode, referenceNode], CallType.NonBlocking); |
| 84 | |
| 85 | if (isIFrame) { |
| 86 | // an iframe element's instanceId is also |
| 87 | // the winId of its contentWindow |
| 88 | const src = getInstanceStateValue<string>(newNode, StateProp.src); |
| 89 | if (src && src.startsWith('javascript:')) { |
| 90 | const scriptContent = src.split('javascript:')[1]; |
| 91 | runScriptContent(env, instanceId, scriptContent, winId, ''); |
| 92 | } |
| 93 | insertIframe(instanceId, newNode); |
| 94 | } |
| 95 | if (isScript) { |
| 96 | sendToMain(true); |
| 97 | webWorkerCtx.$postMessage$([WorkerMessageType.InitializeNextScript, winId]); |
| 98 | } |
| 99 | |
| 100 | return newNode; |
| 101 | } |
| 102 | |
| 103 | get nodeName() { |
| 104 | return this[InstanceDataKey] === '#s' ? '#document-fragment' : this[InstanceDataKey]; |
no test coverage detected