(ExecutionContext context, String name, PropertyDescriptor desc, boolean shouldThrow)
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public boolean defineOwnProperty(ExecutionContext context, String name, PropertyDescriptor desc, boolean shouldThrow) { |
| 32 | // 15.4.5.1 |
| 33 | PropertyDescriptor oldLenDesc = (PropertyDescriptor) getOwnProperty(context, "length"); |
| 34 | long oldLen = (long) oldLenDesc.getValue(); |
| 35 | |
| 36 | if (name.equals("length")) { |
| 37 | if (desc.getValue() == null ) { |
| 38 | return super.defineOwnProperty(context, "length", desc, shouldThrow); |
| 39 | } |
| 40 | |
| 41 | PropertyDescriptor newLenDesc = desc; |
| 42 | Long newLen = Types.toUint32(context, desc.getValue()); |
| 43 | if (!Types.compareEquality(context, newLen, Types.toNumber(context, desc.getValue()))) { |
| 44 | throw new ThrowException(context, context.createRangeError("invalid length: " + newLen)); |
| 45 | } |
| 46 | newLenDesc.setValue(newLen); |
| 47 | if (newLen >= oldLen) { |
| 48 | return super.defineOwnProperty(context, "length", newLenDesc, shouldThrow); |
| 49 | } |
| 50 | |
| 51 | if (!oldLenDesc.hasWritable() && !oldLenDesc.isWritable()) { |
| 52 | return reject(context, shouldThrow); |
| 53 | } |
| 54 | |
| 55 | boolean newWritable = false; |
| 56 | if ((!newLenDesc.hasWritable()) || newLenDesc.isWritable()) { |
| 57 | newWritable = true; |
| 58 | } else { |
| 59 | newWritable = false; |
| 60 | newLenDesc.setWritable(true); |
| 61 | } |
| 62 | |
| 63 | boolean succeeded = super.defineOwnProperty(context, "length", newLenDesc, shouldThrow); |
| 64 | |
| 65 | if (!succeeded) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | while (newLen < oldLen) { |
| 70 | oldLen = oldLen - 1; |
| 71 | boolean deleteSucceeded = delete(context, "" + oldLen, false); |
| 72 | |
| 73 | if (!deleteSucceeded) { |
| 74 | newLenDesc.setValue(oldLen + 1); |
| 75 | if (!newWritable) { |
| 76 | newLenDesc.setWritable(false); |
| 77 | } |
| 78 | super.defineOwnProperty(context, "length", newLenDesc, false); |
| 79 | return reject(context, shouldThrow); |
| 80 | |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (newWritable == false) { |
| 85 | PropertyDescriptor lengthDesc = new PropertyDescriptor(); |
| 86 | lengthDesc.setWritable(false); |
| 87 | super.defineOwnProperty(context, "length", lengthDesc, false); |
no test coverage detected