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