1323 * Set the __proto__ of an object from an object literal. 1324 * See ES6 draft spec: B.3.1 __proto__ Property Names in 1325 * Object Initializers. Step 6 handling of "__proto__". 1326 * 1327 * @param newProto Prototype to set. 1328 */ 1329 public final void setProtoFromLiteral(final Object newProto) { 1330 if (newProto == null || newProto instanceof ScriptObject) { 1331 setPrototypeOf(newProto); 1332 } else { 1333 // Some non-object, non-null. Then, we need to set 1334 // Object.prototype as the new __proto__ 1335 // 1336 // var obj = { __proto__ : 34 }; 1337 // print(obj.__proto__ === Object.prototype); // => true 1338 setPrototypeOf(Global.objectPrototype()); 1339 } 1340 } 1341 1342 /** 1343 * return an array of own property keys associated with the object. 1344 * 1345 * @param all True if to include non-enumerable keys. 1346 * @return Array of keys. 1347 */ 1348 public final String[] getOwnKeys(final boolean all) { 1349 return getOwnKeys(all, null); 1350 } 1351 1352 /** 1353 * return an array of own property keys associated with the object. 1354 * 1355 * @param all True if to include non-enumerable keys. 1356 * @param nonEnumerable set of non-enumerable properties seen already.Used 1357 to filter out shadowed, but enumerable properties from proto children. 1358 * @return Array of keys. 1359 */ 1360 protected String[] getOwnKeys(final boolean all, final Set<String> nonEnumerable) { 1361 final List<Object> keys = new ArrayList<>(); 1362 final PropertyMap selfMap = this.getMap(); | 1323 * Set the __proto__ of an object from an object literal. 1324 * See ES6 draft spec: B.3.1 __proto__ Property Names in 1325 * Object Initializers. Step 6 handling of "__proto__". 1326 * 1327 * @param newProto Prototype to set. 1328 */ 1329 public final void setProtoFromLiteral(final Object newProto) { 1330 if (newProto == null || newProto instanceof ScriptObject) { 1331 setPrototypeOf(newProto); 1332 } else { 1333 // Some non-object, non-null. Then, we need to set 1334 // Object.prototype as the new __proto__ 1335 // 1336 // var obj = { __proto__ : 34 }; 1337 // print(obj.__proto__ === Object.prototype); // => true 1338 setPrototypeOf(Global.objectPrototype()); 1339 } 1340 } 1341 1342 /** 1343 * return an array of all property keys - all inherited, non-enumerable included. 1344 * This is meant for source code completion by interactive shells or editors. 1345 * 1346 * @return Array of keys, order of properties is undefined. 1347 */ 1348 public String[] getAllKeys() { 1349 final Set<String> keys = new HashSet<>(); 1350 final Set<String> nonEnumerable = new HashSet<>(); 1351 for (ScriptObject self = this; self != null; self = self.getProto()) { 1352 keys.addAll(Arrays.asList(self.getOwnKeys(true, nonEnumerable))); 1353 } 1354 return keys.toArray(new String[keys.size()]); 1355 } 1356 1357 /** 1358 * return an array of own property keys associated with the object. 1359 * 1360 * @param all True if to include non-enumerable keys. 1361 * @return Array of keys. 1362 */ 1363 public final String[] getOwnKeys(final boolean all) { 1364 return getOwnKeys(all, null); 1365 } 1366 1367 /** 1368 * return an array of own property keys associated with the object. 1369 * 1370 * @param all True if to include non-enumerable keys. 1371 * @param nonEnumerable set of non-enumerable properties seen already.Used 1372 to filter out shadowed, but enumerable properties from proto children. 1373 * @return Array of keys. 1374 */ 1375 protected String[] getOwnKeys(final boolean all, final Set<String> nonEnumerable) { 1376 final List<Object> keys = new ArrayList<>(); 1377 final PropertyMap selfMap = this.getMap(); |