OLD | NEW |
---|---|
1 description("Make sure prototypes are set up using the window a property came fr om, instead of the lexical global object.") | 1 description("Make sure prototypes are set up using the window a property came fr om, instead of the lexical global object.") |
2 | 2 |
3 var subframe = document.createElement("iframe"); | 3 var subframe = document.createElement("iframe"); |
4 document.body.appendChild(subframe); | 4 document.body.appendChild(subframe); |
5 var inner = subframe.contentWindow; // Call it "inner" to make shouldBe output s horter | 5 var inner = subframe.contentWindow; // Call it "inner" to make shouldBe output s horter |
6 | 6 |
7 // Stash a property on the prototypes. | 7 // Stash a property on the prototypes. |
8 window.Object.prototype.isInner = false; | 8 window.Object.prototype.isInner = false; |
9 inner.Object.prototype.isInner = true; | 9 inner.Object.prototype.isInner = true; |
10 | 10 |
11 function classNameForObject(object) | 11 var constructorNames = ["Image", "MediaController", "Option", "OverflowEvent", " ProgressEvent", "URL", "XMLHttpRequest"]; |
12 { | |
13 // call will use the global object if passed null or undefined, so special c ase those: | |
14 if (object == null) | |
15 return null; | |
16 var result = Object.prototype.toString.call(object); | |
17 // remove '[object ' and ']' | |
18 return result.split(' ')[1].split(']')[0]; | |
19 } | |
20 | |
21 function constructorPropertiesOnWindow(globalObject) | |
22 { | |
23 var constructorNames = []; | |
24 for (var property in globalObject) { | |
arv (Not doing code reviews)
2013/04/24 15:34:08
Can we change the loop to use Object.getOwnPropert
| |
25 var value = inner[property]; | |
26 if (value == null) | |
27 continue; | |
28 var type = classNameForObject(value); | |
29 // Ignore these properties because they do not exist in all implementati ons. They will be tested separately | |
30 if (type == "WebGLRenderingContextConstructor" || | |
31 type == "ArrayBufferConstructor" || | |
32 type =="Float32ArrayConstructor" || | |
33 type =="Float64ArrayConstructor" || | |
34 type =="Int8ArrayConstructor" || | |
35 type =="Int16ArrayConstructor" || | |
36 type =="Int32ArrayConstructor" || | |
37 type =="Uint8ArrayConstructor" || | |
38 type =="Uint8ClampedArrayConstructor" || | |
39 type =="Uint16ArrayConstructor" || | |
40 type =="Uint32ArrayConstructor" || | |
41 type == "FileErrorConstructor" || | |
42 type == "FileReaderConstructor" || | |
43 type == "AudioContextConstructor" || | |
44 type == "SpeechSynthesisUtteranceConstructor") | |
45 continue; | |
46 if (!type.match('Constructor$')) | |
47 continue; | |
48 constructorNames.push(property); | |
49 } | |
50 return constructorNames.sort(); | |
51 } | |
52 | |
53 var constructorNames = constructorPropertiesOnWindow(inner); | |
54 | 12 |
55 var argumentsForConstructor = { | 13 var argumentsForConstructor = { |
56 'Worker' : "'foo'", | 14 'Worker' : "'foo'", |
57 } | 15 } |
58 | 16 |
59 for (var x = 0; x < constructorNames.length; x++) { | 17 for (var x = 0; x < constructorNames.length; x++) { |
60 var constructorName = constructorNames[x]; | 18 var constructorName = constructorNames[x]; |
61 var arguments = argumentsForConstructor[constructorName] || ""; | 19 var arguments = argumentsForConstructor[constructorName] || ""; |
62 var argumentsString = "(" + arguments + ")"; | 20 var argumentsString = "(" + arguments + ")"; |
63 // Test first to see if the object is constructable | 21 // Test first to see if the object is constructable |
64 var constructedObject; | 22 var constructedObject; |
65 try { | 23 try { |
66 constructedObject = eval("new inner." + constructorName + argumentsStrin g); | 24 constructedObject = eval("new inner." + constructorName + argumentsStrin g); |
67 } catch(e) { | 25 } catch(e) { |
68 continue; | 26 continue; |
69 } | 27 } |
70 | 28 |
71 shouldBeTrue("(new inner." + constructorName + argumentsString + ").isInner" ); | 29 shouldBeTrue("(new inner." + constructorName + argumentsString + ").isInner" ); |
72 shouldBeTrue("(new inner." + constructorName + argumentsString + ").construc tor.isInner"); | 30 shouldBeTrue("(new inner." + constructorName + argumentsString + ").construc tor.isInner"); |
73 } | 31 } |
74 | 32 |
75 document.body.removeChild(subframe); | 33 document.body.removeChild(subframe); |
OLD | NEW |