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>> 36stream 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 41var some_object = { "colors": [ "red", "green", "blue"] }; 42 43var 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 63function 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 74function 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 85function 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 97function 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 126dump_global("Initial State"); 127 128// Check that they all exist. 129setup_global(); 130dump_global("After Setup"); 131 132// Test deletion. 133delete_global(); 134dump_global("After Deletion"); 135 136// setPersistent() should be a no-op for pdfium. 137setup_global(); 138persist_global(false); 139dump_global("After Setup and Persist false"); 140 141// Test setting deleted variables as persistent. 142delete_global(); 143persist_global(true); 144dump_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). 148setup_global(); 149persist_global(true); 150dump_global("After Setup and Persist true"); 151 152endstream 153endobj 154{{xref}} 155trailer << 156 /Root 1 0 R 157>> 158{{startxref}} 159%%EOF 160