1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15switch (1) { 16default: 17 var o = { 18 value: 10, 19 func() { 20 return 234 + this.value; 21 }, 22 ["a" + "b"]() { 23 return 456 - this.value; 24 } 25 } 26} 27 28assert(o.func() === 244); 29assert(o.ab() === 446); 30 31switch (1) { 32default: 33 var ab = 5; 34 var cd = 6; 35 o = { 36 ab, 37 cd: 8, 38 cd 39 } 40} 41 42assert(o.ab === 5); 43assert(o.cd === 6); 44 45function exception_expected(str) { 46 try { 47 eval(str); 48 assert(false); 49 } catch (e) { 50 assert(e instanceof SyntaxError); 51 } 52} 53 54// These forms are invalid. 55exception_expected('({ true })'); 56exception_expected('({ 13 })'); 57exception_expected('({ "x" })'); 58 59switch (1) { 60default: 61 // These forms are valid. 62 ({ true: true }); 63 ({ 13: 13 }); 64 ({ "x": "x" }); 65 66 var get = 8; 67 var set = 12; 68 var o = ({ get, set }); 69 70 assert(o.get == 8); 71 assert(o.set == 12); 72} 73 74var obj = { get() { return 5; }, set() { return 6; } }; 75 76assert (obj.get() === 5); 77assert (obj.set() === 6); 78