MCPcopy Create free account
hub / github.com/dynjs/dynjs / defineOwnProperty

Method defineOwnProperty

src/main/java/org/dynjs/runtime/DynArray.java:30–111  ·  view source on GitHub ↗
(ExecutionContext context, String name, PropertyDescriptor desc, boolean shouldThrow)

Source from the content-addressed store, hash-verified

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);

Callers 4

interpretMethod · 0.95
callMethod · 0.95
callMethod · 0.95
visitMethod · 0.95

Calls 15

getValueMethod · 0.95
toUint32Method · 0.95
compareEqualityMethod · 0.95
toNumberMethod · 0.95
setValueMethod · 0.95
hasWritableMethod · 0.95
isWritableMethod · 0.95
setWritableMethod · 0.95
isArrayIndexMethod · 0.95
createRangeErrorMethod · 0.80
rejectMethod · 0.80
getOwnPropertyMethod · 0.65

Tested by

no test coverage detected