Skip to content

Commit 2b8e0c9

Browse files
committed
headless improvements
1 parent 6ef983a commit 2b8e0c9

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/headless.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,15 @@ var document = {
142142
});
143143
return ret;
144144
}
145-
default: throw 'createElement ' + what;
145+
case 'div': {
146+
return {
147+
appendChild: function() {},
148+
requestFullScreen: function() {
149+
return document.getElementById('canvas').requestFullScreen();
150+
},
151+
};
152+
}
153+
default: throw 'createElement ' + what + new Error().stack;
146154
}
147155
},
148156
elements: {},
@@ -236,9 +244,6 @@ var Worker = function(workerPath) {
236244
workerPath = fixPath(workerPath);
237245
var workerCode = read(workerPath);
238246
workerCode = workerCode.replace(/Module/g, 'zzModuleyy' + (Worker.id++)). // prevent collision with the global Module object. Note that this becomes global, so we need unique ids
239-
//replace(/Date.now/g, 'Recorder.dnow'). // recorded values are just for the "main thread" - workers were not recorded, and should not consume
240-
//replace(/performance.now/g, 'Recorder.pnow').
241-
//replace(/Math.random/g, 'Recorder.random').
242247
replace(/\nonmessage = /, '\nvar onmessage = '); // workers commonly do "onmessage = ", we need to varify that to sandbox
243248
headlessPrint('loading worker ' + workerPath + ' : ' + workerCode.substring(0, 50));
244249
eval(workerCode); // will implement onmessage()

src/headlessCanvas.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function headlessCanvas() {
2-
return {
2+
var that = this;
3+
var ret = {
34
headless: true,
45
getContext: function(which) {
56
switch(which) {
@@ -452,7 +453,7 @@ function headlessCanvas() {
452453
}
453454
},
454455
getSupportedExtensions: function() {
455-
return ["OES_texture_float", "OES_standard_derivatives", "EXT_texture_filter_anisotropic"];
456+
return ["OES_texture_float", "OES_standard_derivatives", "EXT_texture_filter_anisotropic", "MOZ_EXT_texture_filter_anisotropic", "MOZ_WEBGL_lose_context", "MOZ_WEBGL_compressed_texture_s3tc", "MOZ_WEBGL_depth_texture"];
456457
},
457458
createShader: function(type) {
458459
var id = this.id++;
@@ -600,7 +601,8 @@ function headlessCanvas() {
600601
},
601602
exitPointerLock: function(){},
602603
style: {
603-
setProperty: function(){}
604+
setProperty: function() {},
605+
removeProperty: function() {},
604606
},
605607
eventListeners: {},
606608
addEventListener: function(){},
@@ -618,6 +620,9 @@ function headlessCanvas() {
618620
add: function(){},
619621
remove: function(){},
620622
},
623+
insertBefore: function(){},
621624
};
625+
ret.parentNode = ret;
626+
return ret;
622627
}
623628

0 commit comments

Comments
 (0)