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

Method defineOwnProperty

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

Source from the content-addressed store, hash-verified

322 }
323
324 @Override
325 public boolean defineOwnProperty(ExecutionContext context, String name, PropertyDescriptor desc, boolean shouldThrow) {
326 // 8.12.9
327 Object c = getOwnProperty(context, name, false);
328
329 if (c == Types.UNDEFINED) {
330 if (!isExtensible()) {
331 return reject(context, shouldThrow);
332 } else {
333 // System.err.println("DEF.initial: " + name + " > " + newDesc);
334 this.properties.put(name, desc.duplicateWithDefaults());
335 return true;
336 }
337 }
338
339 if (desc.isEmpty()) {
340 return true;
341 }
342
343 PropertyDescriptor current = (PropertyDescriptor) c;
344
345 if (current.hasConfigurable() && !current.isConfigurable()) {
346 if (desc.hasConfigurable() && desc.isConfigurable()) {
347 return reject(context, shouldThrow);
348 }
349
350 if (current.hasEnumerable() && desc.hasEnumerable() && current.isEnumerable() != desc.isEnumerable()) {
351 return reject(context, shouldThrow);
352 }
353 }
354
355 PropertyDescriptor newDesc = null;
356
357 if (desc.isGenericDescriptor()) {
358 newDesc = new PropertyDescriptor();
359 newDesc.copyAll(current);
360 // System.err.println("DEF.generic: " + name + " > " + newDesc);
361 } else if (current.isDataDescriptor() != desc.isDataDescriptor()) {
362 if (!current.isConfigurable()) {
363 return reject(context, shouldThrow);
364 }
365 if (current.isDataDescriptor()) {
366 // System.err.println("accessor");
367 newDesc = PropertyDescriptor.newAccessorPropertyDescriptor();
368 } else {
369 // System.err.println("data");
370 newDesc = PropertyDescriptor.newDataPropertyDescriptor();
371 }
372 // System.err.println("DEF.mismatch: " + name + " > " + newDesc);
373 } else if (current.isDataDescriptor() && desc.isDataDescriptor()) {
374 if (!current.isConfigurable()) {
375 if (current.hasWritable() && !current.isWritable()) {
376 if (desc.isWritable()) {
377 return reject(context, shouldThrow);
378 }
379 Object newValue = desc.getValue();
380 if (newValue != null && !Types.sameValue(current.getValue(), newValue)) {
381 return reject(context, shouldThrow);

Callers 11

interpretMethod · 0.95
createArgumentsObjectMethod · 0.95
putMethod · 0.95
parseObjectMethod · 0.95
callMethod · 0.95
callMethod · 0.95
JavascriptFunctionMethod · 0.95
visitMethod · 0.95

Calls 15

getOwnPropertyMethod · 0.95
isExtensibleMethod · 0.95
rejectMethod · 0.95
hasConfigurableMethod · 0.95
isConfigurableMethod · 0.95
hasEnumerableMethod · 0.95
isEnumerableMethod · 0.95
copyAllMethod · 0.95
isDataDescriptorMethod · 0.95
hasWritableMethod · 0.95

Tested by

no test coverage detected