OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Copyright 2011 the V8 project authors. All rights reserved. | |
adamk
2012/10/23 16:29:44
Woops, duplicated license
rafaelw
2012/10/23 21:21:35
Done.
| |
29 // Redistribution and use in source and binary forms, with or without | |
30 // modification, are permitted provided that the following conditions are | |
31 // met: | |
32 // | |
33 // * Redistributions of source code must retain the above copyright | |
34 // notice, this list of conditions and the following disclaimer. | |
35 // * Redistributions in binary form must reproduce the above | |
36 // copyright notice, this list of conditions and the following | |
37 // disclaimer in the documentation and/or other materials provided | |
38 // with the distribution. | |
39 // * Neither the name of Google Inc. nor the names of its | |
40 // contributors may be used to endorse or promote products derived | |
41 // from this software without specific prior written permission. | |
42 // | |
43 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | |
55 // Flags: --harmony-object-observe | |
56 | |
57 (function() { | |
58 var obj = {}; | |
59 var records; | |
60 var callbackCount = 0; | |
61 function obs(r) { | |
62 callbackCount++; | |
63 records = r; | |
64 } | |
65 | |
66 function frozenFunction() {} | |
67 Object.freeze(frozenFunction); | |
68 var nonFunction = {}; | |
69 | |
70 // Object.observe | |
71 assertThrows(function() { Object.observe("non-object", obs); }, TypeError); | |
72 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); | |
73 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); | |
74 | |
75 // Object.unobserve | |
adamk
2012/10/23 16:29:44
Seems like a test for unobserve's functionality wo
rafaelw
2012/10/23 21:21:35
Done.
| |
76 assertThrows(function() { Object.unobserve(4, obs); }, TypeError); | |
77 | |
78 // Object.notify | |
79 assertThrows(function() { Object.notify(obs, {}); }, TypeError); | |
80 assertThrows(function() { Object.notify(obs, { type: 4 }); }, TypeError); | |
81 | |
82 // Object.deliverChangeRecords | |
83 assertThrows(function() { Object.deliverChangeRecords(nonFunction); }, TypeErr or); | |
84 | |
85 Object.observe(obj, obs); | |
86 Object.notify(obj, { | |
87 object: obj, | |
88 type: 'updated', | |
89 name: 'foo', | |
90 expando: 1 | |
91 }); | |
92 | |
93 Object.notify(obj, { | |
94 object: obj, | |
95 type: 'deleted', | |
96 name: 'bar', | |
97 expando2: 'str' | |
98 }); | |
99 Object.deliverChangeRecords(obs); | |
100 assertEquals(1, callbackCount); | |
101 assertEquals(2, records.length); | |
102 assertEquals(obj, records[0].object); | |
103 assertEquals('foo', records[0].name); | |
104 assertEquals('updated', records[0].type); | |
105 assertEquals(1, records[0].expando); | |
106 assertEquals(obj, records[1].object); | |
107 assertEquals('bar', records[1].name); | |
108 assertEquals('deleted', records[1].type); | |
109 assertEquals('str', records[1].expando2); | |
110 assertEquals(undefined, records[1].expando); | |
111 | |
112 records = undefined; | |
113 Object.deliverChangeRecords(obs); | |
114 assertEquals(1, callbackCount); | |
115 assertEquals(undefined, records); | |
116 })() | |
OLD | NEW |