xref: /aosp_15_r20/external/pdfium/testing/resources/javascript/icons.in (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1{{header}}
2{{include field.fragment}}
3{{object 16 0}} <<
4  {{streamlen}}
5>>
6stream
7// In order to get icons from a document, you have to first add icons
8// to the document, and the only way to initially get an icon object,
9// it would seem, is from a button in a field. Then it can be added
10// any number of times, which does nothing but accumulate the list of
11// names of the added icons. Whee.
12try {
13  var doc = this;
14  app.alert("doc is " + doc);
15  var icon = doc.getField("MyField.MyPushButton").buttonGetIcon();
16  app.alert("icon is " + icon);
17  doc.addIcon("icon1", icon);
18  doc.addIcon("icon2", icon);
19  app.alert("icon list is now " + doc.icons);
20  var icon1 = doc.icons[0];
21  var icon2 = doc.icons[1];
22  app.alert("they are named " + icon1.name + " and " + icon2.name);
23  var icon1_again = doc.getIcon("icon1");
24  var icon2_again = doc.getIcon("icon2");
25  app.alert("they are also named " + icon1_again.name +
26            " and " + icon2_again.name);
27  app.alert("but they are made anew each time since " +
28             (icon1 == icon1_again) + " is returned from comparison");
29  app.alert("Prototype comparison is " + (icon1.__proto__ == icon1_again.__proto__));
30
31  // Icons are "dynamic" objects, so theoretically we can make them from
32  // the JS side as well, although they will not be bound on the fxjs side.
33  var dubious = new icon1.constructor();
34  app.alert("Made anew from JS side since comparison is " + (dubious == icon1));
35  app.alert("Prototype comparison is " + (dubious.__proto__ == icon1.__proto__));
36
37  // Can't retrieve the name because no fxjs binding present.
38  app.alert("Dubious name is " + dubious.name);
39
40  // No error setting the name because for an unbound object, control doesn't
41  // get far enough to reach the readonly check in the property handler.
42  dubious.name = "pebble";
43
44  // The previous was a silent no-op under the covers.
45  app.alert("name is unchanged from " + dubious.name);
46} catch (e) {
47  app.alert("error: " + e);
48}
49try {
50  icon1.name = "chowder";
51} catch (e) {
52  app.alert("As expected, trying to change the name gave: " + e);
53}
54endstream
55endobj
56{{xref}}
57{{trailer}}
58{{startxref}}
59%%EOF
60