|
| 1 | +var document = { |
| 2 | + createElement: function() { |
| 3 | + return { |
| 4 | + style: {}, |
| 5 | + setAttribute: function() {}, |
| 6 | + getAttribute: function() { return null; }, |
| 7 | + hasAttribute: function() { return false; }, |
| 8 | + appendChild: function(c) { return c; }, |
| 9 | + removeChild: function(c) { return c; }, |
| 10 | + addEventListener: function() {}, |
| 11 | + getBoundingClientRect: function() { return {top:0,left:0,right:0,bottom:0,width:0,height:0,x:0,y:0}; } |
| 12 | + }; |
| 13 | + }, |
| 14 | + createEvent: function(type) { |
| 15 | + return { |
| 16 | + initEvent: function(t, bubbles, cancelable) { this.type = t; this.bubbles = bubbles; this.cancelable = cancelable; }, |
| 17 | + type: '', |
| 18 | + bubbles: false, |
| 19 | + cancelable: false, |
| 20 | + preventDefault: function() {} |
| 21 | + }; |
| 22 | + }, |
| 23 | + getElementById: function(id) { return id === 'videoDiv' ? this.createElement() : null; }, |
| 24 | + querySelector: function(s) { return s === '#videoDiv' ? this.getElementById('videoDiv') : null; }, |
| 25 | + body: { appendChild: function(c) { return c; } }, |
| 26 | + head: { appendChild: function(c) { return c; } } |
| 27 | +}; |
| 28 | + |
| 29 | +function Event(t) { this.type = t; } |
| 30 | +Event.prototype.preventDefault = function() {}; |
| 31 | + |
| 32 | +function DOMParser() {} |
| 33 | +DOMParser.prototype.parseFromString = function() { return document; }; |
| 34 | + |
| 35 | +function Blob(parts, options) { this.size = 0; this.type = (options && options.type) || ''; } |
| 36 | +Blob.prototype.slice = function() { return new Blob([], {}); }; |
| 37 | + |
| 38 | +// AbortController for fetch API |
| 39 | +function AbortController() { |
| 40 | + this.signal = { aborted: false, addEventListener: function() {} }; |
| 41 | +} |
| 42 | +AbortController.prototype.abort = function() { |
| 43 | + this.signal.aborted = true; |
| 44 | +}; |
| 45 | + |
| 46 | +// Minimal fetch stub |
| 47 | +function fetch(url, options) { |
| 48 | + return new Promise(function(resolve, reject) { |
| 49 | + if (options && options.signal && options.signal.aborted) { |
| 50 | + var error = new Error('Aborted'); |
| 51 | + error.name = 'AbortError'; |
| 52 | + reject(error); |
| 53 | + return; |
| 54 | + } |
| 55 | + // Stub response |
| 56 | + resolve({ |
| 57 | + ok: true, |
| 58 | + status: 200, |
| 59 | + json: function() { return Promise.resolve({}); }, |
| 60 | + text: function() { return Promise.resolve(''); }, |
| 61 | + blob: function() { return Promise.resolve(new Blob([], {})); } |
| 62 | + }); |
| 63 | + }); |
| 64 | +} |
| 65 | + |
| 66 | +// Wrap timer functions to ensure .apply() works |
| 67 | +var _setTimeout = setTimeout; |
| 68 | +var _setInterval = setInterval; |
| 69 | +var _clearTimeout = clearTimeout; |
| 70 | +var _clearInterval = clearInterval; |
| 71 | + |
| 72 | +function wrappedSetTimeout(fn, delay) { |
| 73 | + var args = Array.prototype.slice.call(arguments, 2); |
| 74 | + return _setTimeout(function() { fn.apply(null, args); }, delay); |
| 75 | +} |
| 76 | +wrappedSetTimeout.apply = function(thisArg, argArray) { |
| 77 | + if (!argArray || argArray.length === 0) return _setTimeout(); |
| 78 | + if (argArray.length === 1) return _setTimeout(argArray[0]); |
| 79 | + if (argArray.length === 2) return _setTimeout(argArray[0], argArray[1]); |
| 80 | + var args = Array.prototype.slice.call(argArray, 2); |
| 81 | + return _setTimeout(function() { argArray[0].apply(null, args); }, argArray[1]); |
| 82 | +}; |
| 83 | + |
| 84 | +function wrappedSetInterval(fn, delay) { |
| 85 | + var args = Array.prototype.slice.call(arguments, 2); |
| 86 | + return _setInterval(function() { fn.apply(null, args); }, delay); |
| 87 | +} |
| 88 | +wrappedSetInterval.apply = function(thisArg, argArray) { |
| 89 | + if (!argArray || argArray.length === 0) return _setInterval(); |
| 90 | + if (argArray.length === 1) return _setInterval(argArray[0]); |
| 91 | + if (argArray.length === 2) return _setInterval(argArray[0], argArray[1]); |
| 92 | + var args = Array.prototype.slice.call(argArray, 2); |
| 93 | + return _setInterval(function() { argArray[0].apply(null, args); }, argArray[1]); |
| 94 | +}; |
| 95 | + |
| 96 | +function wrappedClearTimeout(id) { return _clearTimeout(id); } |
| 97 | +wrappedClearTimeout.apply = function(thisArg, argArray) { |
| 98 | + return _clearTimeout(argArray ? argArray[0] : undefined); |
| 99 | +}; |
| 100 | + |
| 101 | +function wrappedClearInterval(id) { return _clearInterval(id); } |
| 102 | +wrappedClearInterval.apply = function(thisArg, argArray) { |
| 103 | + return _clearInterval(argArray ? argArray[0] : undefined); |
| 104 | +}; |
| 105 | + |
| 106 | +var window = { |
| 107 | + document: document, |
| 108 | + location: {href:'',host:'127.0.0.1',hostname:'127.0.0.1'}, |
| 109 | + navigator: {userAgent:'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36',platform:'Linux'}, |
| 110 | + console: console, |
| 111 | + setTimeout: wrappedSetTimeout, |
| 112 | + setInterval: wrappedSetInterval, |
| 113 | + clearTimeout: wrappedClearTimeout, |
| 114 | + clearInterval: wrappedClearInterval, |
| 115 | + addEventListener: function() {}, |
| 116 | + Event: Event, |
| 117 | + DOMParser: DOMParser, |
| 118 | + Blob: Blob, |
| 119 | + AbortController: AbortController, |
| 120 | + fetch: fetch, |
| 121 | + Promise: Promise |
| 122 | +}; |
| 123 | + |
| 124 | +window.window = window; |
| 125 | +window.self = window; |
| 126 | +var navigator = window.navigator; |
| 127 | +var location = window.location; |
| 128 | +window.top = window; |
| 129 | +var tv = window.tv = {}; |
| 130 | +var DOMParser = window.DOMParser; |
| 131 | +var Event = window.Event; |
| 132 | +var Blob = window.Blob; |
| 133 | +var AbortController = window.AbortController; |
| 134 | +var fetch = window.fetch; |
| 135 | +var Promise = window.Promise; |
| 136 | +var top = window; |
| 137 | +var setTimeout = wrappedSetTimeout; |
| 138 | +var setInterval = wrappedSetInterval; |
| 139 | +var clearTimeout = wrappedClearTimeout; |
| 140 | +var clearInterval = wrappedClearInterval; |
| 141 | +var LinkedJSDOMLib = {parseHTML: function() { return {window:window,document:document,defaultView:window}; }}; |
0 commit comments