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