2d.getContext.options.any.js (1308B)
1 test(() => { 2 const expected = [ 3 "alpha", 4 "colorSpace", 5 "colorSpace toString", 6 "desynchronized", 7 "willReadFrequently", 8 ]; 9 var actual = []; 10 const options = { 11 get alpha() { 12 actual.push("alpha"); 13 return true; 14 }, 15 get willReadFrequently() { 16 actual.push("willReadFrequently"); 17 return false; 18 }, 19 get desynchronized() { 20 actual.push("desynchronized"); 21 return false; 22 }, 23 get colorSpace() { 24 actual.push("colorSpace"); 25 return { 26 toString() { 27 actual.push("colorSpace toString"); 28 return "srgb"; 29 } 30 }; 31 }, 32 }; 33 34 const canvas = new OffscreenCanvas(100, 50); 35 const context = canvas.getContext('2d', options); 36 assert_not_equals(context, null, "context"); 37 assert_array_equals(actual, expected, "order of operations (creation)"); 38 actual = []; 39 assert_equals(canvas.getContext('2d', options), context, "cached context"); 40 // Getting the cached context does not involve the options argument at all; 41 // the context retains its existing settings, and the new options (if any) 42 // are ignored. 43 // Therefore, there is no expectation that the 'options' dictionary will be 44 // accessed again here, and we cannot predict the contents, if any, of the 45 // 'actual' array. 46 });