Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: test/webkit/array-defineOwnProperty.js

Issue 18068003: Migrated several tests from blink to V8 repository. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
6 // are met:
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24 description("This test checks the behavior of [[DefineOwnProperty]] applied to A rray objects (see ES5.1 15.4.5.1).");
25
26 // Test that properties other than length, array indices are handled as normal.
27 shouldBeTrue("Object.defineProperty([], 'x', { get:function(){return true;} }).x ");
28
29 // The length property can be set, and can be made read-only.
30 shouldBe("Object.defineProperty([], 'length', { value: 1 }).length", '1');
31 shouldBe("var a = Object.defineProperty([], 'length', { writable: false }); a[1] = 1; a.length", '0');
32 shouldBe("var a = Object.defineProperty([], 'length', { writable: false }); a.le ngth = 1; a.length", '0');
33 // If writable is not specified, it should not change.
34 shouldBe("var a = Object.defineProperty([], 'length', {}); a.length = 1; a.lengt h", '1');
35
36 // The length property can be replaced with an accessor, or made either enumerab le or configurable.
37 shouldThrow("Object.defineProperty([], 'length', { get:function(){return true;} })");
38 shouldThrow("Object.defineProperty([], 'length', { enumerable: true })");
39 shouldThrow("Object.defineProperty([], 'length', { configurable: true })");
40 shouldThrow("Object.defineProperty(Object.defineProperty([], 'length', { writabl e: false }), 'length', { writable: true })");
41
42 // The value of an indexed property can be set.
43 shouldBe("var a = Object.defineProperty([], '0', { value: 42 }); a[0]", '42');
44 // An indexed property can be made non-writable/enumerable/configurable.
45 shouldBe("var a = Object.defineProperty([42], '0', { writable: false }); a[0] = 1; a[0]", '42');
46 shouldBe("var a = Object.defineProperty([42], '0', { enumerable: false }); a[0] + Object.keys(a).length", '42');
47 shouldBe("var a = Object.defineProperty([42], '0', { configurable: false }); a.l ength = 0; a[0]", '42');
48 // An indexed property can be defined as an accessor.
49 shouldBe("var foo = 0; Object.defineProperty([], '0', { set:function(x){foo = x; } })[0] = 42; foo", '42');
50 shouldBeTrue("Object.defineProperty([], '0', { get:function(){return true;} })[0 ]")
51 // A configurable, non-writable property can be made writable, but a non-configu rable one cannot.
52 shouldBeTrue("Object.defineProperty(Object.defineProperty([true], '0', { configu rable:true, writable: false }), '0', { writable: true })[0]");
53 shouldThrow("Object.defineProperty(Object.defineProperty([true], '0', { configur able:false, writable: false }), '0', { writable: true })[0]");
54
55 // Reassigning the value is okay if the property is writable.
56 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: 1, writa ble:true }), '0', { value: 2 })[0]", '2');
57 // Reassigning the value is okay if the value doesn't change.
58 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: 1 }), '0 ', { value: 1 })[0]", '1');
59 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: Number.N aN }), '0', { value: -Number.NaN })[0]", 'Number.NaN');
60 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: 'okay'.s ubstring(0,2) }), '0', { value: 'not ok'.substring(4,6) })[0]", '"ok"');
61 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: true }), '0', { value: true })[0]", 'true');
62 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: false }) , '0', { value: false })[0]", 'false');
63 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: null }), '0', { value: null })[0]", 'null');
64 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: undefine d }), '0', { value: undefined })[0]", 'undefined');
65 shouldBe("Object.defineProperty(Object.defineProperty([], '0', { value: Math }), '0', { value: Math })[0]", 'Math');
66 // Reassigning the value is not okay if the value changes.
67 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: 1 }), '0', { value: 2 })[0]");
68 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: 'okay ' }), '0', { value: 'not ok' })[0]");
69 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: true }), '0', { value: false })[0]");
70 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: false }), '0', { value: true })[0]");
71 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: Math }), '0', { value: Object })[0]");
72 // Reassigning the value is not okay if the type changes.
73 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: null }), '0', { value: undefined })[0]");
74 shouldThrow("Object.defineProperty(Object.defineProperty([], '0', { value: undef ined }), '0', { value: null })[0]");
75
76 Object.defineProperty(Array.prototype, "0", { set: function () { throw false; } });
77 Object.defineProperty(Array.prototype, "1", { set: function () { throw false; } });
78 var arrObj = [ , false ];
79 Object.defineProperty(arrObj, "0", { set: function (x) { this.set = x === 42; } });
80 shouldBeTrue("arrObj[0] = 42; arrObj.set;");
81 shouldBeTrue("arrObj[1] = true; arrObj[1];");
82
83 successfullyParsed = true;
OLDNEW
« no previous file with comments | « test/webkit/array-constructor-host-call-expected.txt ('k') | test/webkit/array-defineOwnProperty-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698