1 {{header}} 2 {{object 1 0}} << 3 /Type /Catalog 4 /Pages 2 0 R 5 /OpenAction 10 0 R 6 >> 7 endobj 8 {{object 2 0}} << 9 /Type /Pages 10 /Count 1 11 /Kids [ 12 3 0 R 13 ] 14 >> 15 endobj 16 % Page number 0. 17 {{object 3 0}} << 18 /Type /Page 19 /Parent 2 0 R 20 /Resources << 21 /Font <</F1 15 0 R>> 22 >> 23 /Contents [21 0 R] 24 /MediaBox [0 0 612 792] 25 >> 26 % OpenAction action 27 {{object 10 0}} << 28 /Type /Action 29 /S /JavaScript 30 /JS 11 0 R 31 >> 32 endobj 33 % JS program to exexute 34 {{object 11 0}} << 35 >> 36 stream 37 // The "global" object stores data in a C-like manner, and 38 // can theoretically persist them between sessions (though 39 // pdfium deliberately excludes that functionality). 40 41 var some_object = { "colors": [ "red", "green", "blue"] }; 42 43 var props_to_test = [ 44 // Cover both bool values. 45 { "name": "true_var", "value": true }, 46 { "name": "false_var", "value": false }, 47 48 // Include both zero and a number with some fractional digits. 49 { "name": "zero_var", "value": 0 }, 50 { "name": "number_var", "value": -3.918 }, 51 52 // TODO(tsepez): unicode doesn't seem to survive. 53 { "name": "string_var", "value": "This is a string" }, 54 55 // Try a complex object. 56 { "name": "object_var", "value": some_object }, 57 58 // Test null and undefined. 59 { "name": "null_var", "value": null }, 60 { "name": "undefined_var", "value": undefined } 61 ]; 62 63 function setup_global() { 64 for (var i = 0; i < props_to_test.length; ++i) { 65 var prop = props_to_test[i]; 66 try { 67 global[prop.name] = prop.value; 68 } catch (e) { 69 app.alert("For " + prop.name + ": Setup: ERROR: " + e.toString()); 70 } 71 } 72 } 73 74 function delete_global() { 75 for (var i = 0; i < props_to_test.length; ++i) { 76 var prop = props_to_test[i]; 77 try { 78 delete global[prop.name]; 79 } catch (e) { 80 app.alert("For " + prop.name + ": Delete: ERROR: " + e.toString()); 81 } 82 } 83 } 84 85 function persist_global(should_persist) { 86 for (var i = 0; i < props_to_test.length; ++i) { 87 var prop = props_to_test[i]; 88 try { 89 global.setPersistent(prop.name, should_persist); 90 } catch (e) { 91 app.alert("For " + prop.name + 92 ": Set Persistent: ERROR: " + e.toString()); 93 } 94 } 95 } 96 97 function dump_global(msg) { 98 app.alert("************ " + msg + " ************"); 99 app.alert("Enumerable Globals:"); 100 for (var name in global) { 101 try { 102 app.alert(" " + name + " = " + global[name] + 103 ", own property = " + global.hasOwnProperty(name)); 104 } catch (e) { 105 app.alert("For " + name + ": Dump: ERROR: " + e.toString()); 106 } 107 } 108 app.alert("Expected Globals:"); 109 for (var i = 0; i < props_to_test.length; ++i) { 110 var prop = props_to_test[i]; 111 try { 112 var actual = global[prop.name]; 113 app.alert(" " + prop.name + " = " + actual); 114 if (actual != null && typeof actual == "object") { 115 app.alert(" " + actual.colors[0]); 116 app.alert(" " + actual.colors[1]); 117 app.alert(" " + actual.colors[2]); 118 } 119 } catch (e) { 120 app.alert("For " + prop.name + 121 ": Dump Expected: ERROR: " + e.toString()); 122 } 123 } 124 } 125 126 dump_global("Initial State"); 127 128 // Check that they all exist. 129 setup_global(); 130 dump_global("After Setup"); 131 132 // Test deletion. 133 delete_global(); 134 dump_global("After Deletion"); 135 136 // setPersistent() should be a no-op for pdfium. 137 setup_global(); 138 persist_global(false); 139 dump_global("After Setup and Persist false"); 140 141 // Test setting deleted variables as persistent. 142 delete_global(); 143 persist_global(true); 144 dump_global("After Delete and Persist"); 145 146 // Exit with variables marked as persistent to test whatever path 147 // may exist to persist them (should be igonored on pdfium). 148 setup_global(); 149 persist_global(true); 150 dump_global("After Setup and Persist true"); 151 152 endstream 153 endobj 154 {{xref}} 155 trailer << 156 /Root 1 0 R 157 >> 158 {{startxref}} 159 %%EOF 160