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