| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 bar: float32 | 228 bar: float32 |
| 229 }); | 229 }); |
| 230 | 230 |
| 231 let obj1 = type1(); | 231 let obj1 = type1(); |
| 232 let obj2 = type2(); | 232 let obj2 = type2(); |
| 233 ok("foo" in obj1, "Superclass property exists in superclass"); | 233 ok("foo" in obj1, "Superclass property exists in superclass"); |
| 234 ok(!("bar" in obj1), "Subclass property doesn't exist in superclass"); | 234 ok(!("bar" in obj1), "Subclass property doesn't exist in superclass"); |
| 235 ok("foo" in obj2, "Superclass property exists in subclass"); | 235 ok("foo" in obj2, "Superclass property exists in subclass"); |
| 236 ok("bar" in obj2, "Subclass property exists in subclass"); | 236 ok("bar" in obj2, "Subclass property exists in subclass"); |
| 237 | 237 |
| 238 ok(type1.isinstance(obj1), "Object is recognized as instance of its class"); | 238 ok(type1.isInstance(obj1), "Object is recognized as instance of its class"); |
| 239 ok(type1.isinstance(obj2), "Object is recognized as instance of its supercla
ss"); | 239 ok(type1.isInstance(obj2), "Object is recognized as instance of its supercla
ss"); |
| 240 ok(!type2.isinstance(obj1), "Object isn't an instance of its subclass"); | 240 ok(!type2.isInstance(obj1), "Object isn't an instance of its subclass"); |
| 241 ok(type2.isinstance(obj2), "Object is recognized as instance of its class"); | 241 ok(type2.isInstance(obj2), "Object is recognized as instance of its class"); |
| 242 | 242 |
| 243 // Method and constructor inheritance | 243 // Method and constructor inheritance |
| 244 let type3 = new ObjectType({ | 244 let type3 = new ObjectType({ |
| 245 x: uint8, | 245 x: uint8, |
| 246 foo: function(n) {return this.x * n;} | 246 foo: function(n) {return this.x * n;} |
| 247 }, { | 247 }, { |
| 248 constructor: function(x) | 248 constructor: function(x) |
| 249 { | 249 { |
| 250 this.x = x; | 250 this.x = x; |
| 251 } | 251 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 equal(obj4.x, 6, "Subclass constructor executed correctly"); | 267 equal(obj4.x, 6, "Subclass constructor executed correctly"); |
| 268 | 268 |
| 269 equal(typeof obj3.foo, "function", "Superclass method exists in superclass")
; | 269 equal(typeof obj3.foo, "function", "Superclass method exists in superclass")
; |
| 270 equal(typeof obj3.bar, "undefined", "Subclass method doesn't exist in superc
lass"); | 270 equal(typeof obj3.bar, "undefined", "Subclass method doesn't exist in superc
lass"); |
| 271 equal(typeof obj4.foo, "function", "Superclass method exists in subclass"); | 271 equal(typeof obj4.foo, "function", "Superclass method exists in subclass"); |
| 272 equal(typeof obj4.bar, "function", "Subclass method exists in subclass"); | 272 equal(typeof obj4.bar, "function", "Subclass method exists in subclass"); |
| 273 | 273 |
| 274 equal(obj3.foo(4), 8, "Superclass method executed correctly"); | 274 equal(obj3.foo(4), 8, "Superclass method executed correctly"); |
| 275 equal(obj4.foo(4), 30, "Overridden superclass method executed correctly") | 275 equal(obj4.foo(4), 30, "Overridden superclass method executed correctly") |
| 276 | 276 |
| 277 let type5 = type3.extend({ |
| 278 y: uint8 |
| 279 }); |
| 280 let obj5 = type5(4); |
| 281 equal(obj5.x, 4, "Superclass constructor is called even if subclass has no c
onstructor"); |
| 282 |
| 277 // Untypical overrides | 283 // Untypical overrides |
| 278 type3.extend({x: uint8}); | 284 type3.extend({x: uint8}); |
| 279 ok(true, "Overriding property without changing type"); | 285 ok(true, "Overriding property without changing type"); |
| 280 | 286 |
| 281 throws(function() | 287 throws(function() |
| 282 { | 288 { |
| 283 type3.extend({x: float32}); | 289 type3.extend({x: float32}); |
| 284 }, "Override changes property type"); | 290 }, "Override changes property type"); |
| 285 | 291 |
| 286 throws(function() | 292 throws(function() |
| 287 { | 293 { |
| 288 type3.extend({foo: uint8}); | 294 type3.extend({foo: uint8}); |
| 289 }, "Property masks method"); | 295 }, "Property masks method"); |
| 290 | 296 |
| 291 throws(function() | 297 throws(function() |
| 292 { | 298 { |
| 293 type3.extend({x: function() {}}); | 299 type3.extend({x: function() {}}); |
| 294 }, "Method masks property"); | 300 }, "Method masks property"); |
| 295 }); | 301 }); |
| 296 })(); | 302 })(); |
| LEFT | RIGHT |