src/jdk/nashorn/internal/runtime/ScriptObject.java

Print this page




 452                 // add a new own property
 453                 addOwnProperty(key, desc);
 454                 return true;
 455             }
 456             // new property added to non-extensible object
 457             if (reject) {
 458                 throw typeError(global, "object.non.extensible", name, ScriptRuntime.safeToString(this));
 459             }
 460             return false;
 461         }
 462         // modifying an existing property
 463         final PropertyDescriptor currentDesc = (PropertyDescriptor) current;
 464         final PropertyDescriptor newDesc     = desc;
 465 
 466         if (newDesc.type() == PropertyDescriptor.GENERIC &&
 467             ! newDesc.has(CONFIGURABLE) && ! newDesc.has(ENUMERABLE)) {
 468             // every descriptor field is absent
 469             return true;
 470         }
 471 
 472         if (currentDesc.equals(newDesc)) {
 473             // every descriptor field of the new is same as the current
 474             return true;
 475         }
 476 
 477         if (! currentDesc.isConfigurable()) {
 478             if (newDesc.has(CONFIGURABLE) && newDesc.isConfigurable()) {
 479                 // not configurable can not be made configurable
 480                 if (reject) {
 481                     throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this));
 482                 }
 483                 return false;
 484             }
 485 
 486             if (newDesc.has(ENUMERABLE) &&
 487                 currentDesc.isEnumerable() != newDesc.isEnumerable()) {
 488                 // cannot make non-enumerable as enumerable or vice-versa
 489                 if (reject) {
 490                     throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this));
 491                 }
 492                 return false;




 452                 // add a new own property
 453                 addOwnProperty(key, desc);
 454                 return true;
 455             }
 456             // new property added to non-extensible object
 457             if (reject) {
 458                 throw typeError(global, "object.non.extensible", name, ScriptRuntime.safeToString(this));
 459             }
 460             return false;
 461         }
 462         // modifying an existing property
 463         final PropertyDescriptor currentDesc = (PropertyDescriptor) current;
 464         final PropertyDescriptor newDesc     = desc;
 465 
 466         if (newDesc.type() == PropertyDescriptor.GENERIC &&
 467             ! newDesc.has(CONFIGURABLE) && ! newDesc.has(ENUMERABLE)) {
 468             // every descriptor field is absent
 469             return true;
 470         }
 471 
 472         if (newDesc.hasAndEquals(currentDesc)) {
 473             // every descriptor field of the new is same as the current
 474             return true;
 475         }
 476 
 477         if (! currentDesc.isConfigurable()) {
 478             if (newDesc.has(CONFIGURABLE) && newDesc.isConfigurable()) {
 479                 // not configurable can not be made configurable
 480                 if (reject) {
 481                     throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this));
 482                 }
 483                 return false;
 484             }
 485 
 486             if (newDesc.has(ENUMERABLE) &&
 487                 currentDesc.isEnumerable() != newDesc.isEnumerable()) {
 488                 // cannot make non-enumerable as enumerable or vice-versa
 489                 if (reject) {
 490                     throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this));
 491                 }
 492                 return false;