src/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
*** 323,344 ****
* ECMA 8.10.5 ToPropertyDescriptor ( Obj )
*
* @return property descriptor
*/
public final PropertyDescriptor toPropertyDescriptor() {
! final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
final PropertyDescriptor desc;
if (isDataDescriptor()) {
if (has(SET) || has(GET)) {
! throw typeError((ScriptObject)global, "inconsistent.property.descriptor");
}
desc = global.newDataDescriptor(UNDEFINED, false, false, false);
} else if (isAccessorDescriptor()) {
if (has(VALUE) || has(WRITABLE)) {
! throw typeError((ScriptObject)global, "inconsistent.property.descriptor");
}
desc = global.newAccessorDescriptor(UNDEFINED, UNDEFINED, false, false);
} else {
desc = global.newGenericDescriptor(false, false);
--- 323,344 ----
* ECMA 8.10.5 ToPropertyDescriptor ( Obj )
*
* @return property descriptor
*/
public final PropertyDescriptor toPropertyDescriptor() {
! final Global global = Context.getGlobal();
final PropertyDescriptor desc;
if (isDataDescriptor()) {
if (has(SET) || has(GET)) {
! throw typeError(global, "inconsistent.property.descriptor");
}
desc = global.newDataDescriptor(UNDEFINED, false, false, false);
} else if (isAccessorDescriptor()) {
if (has(VALUE) || has(WRITABLE)) {
! throw typeError(global, "inconsistent.property.descriptor");
}
desc = global.newAccessorDescriptor(UNDEFINED, UNDEFINED, false, false);
} else {
desc = global.newGenericDescriptor(false, false);
*** 353,363 ****
* @param global global scope object
* @param obj object to create property descriptor from
*
* @return property descriptor
*/
! public static PropertyDescriptor toPropertyDescriptor(final ScriptObject global, final Object obj) {
if (obj instanceof ScriptObject) {
return ((ScriptObject)obj).toPropertyDescriptor();
}
throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj));
--- 353,363 ----
* @param global global scope object
* @param obj object to create property descriptor from
*
* @return property descriptor
*/
! public static PropertyDescriptor toPropertyDescriptor(final Global global, final Object obj) {
if (obj instanceof ScriptObject) {
return ((ScriptObject)obj).toPropertyDescriptor();
}
throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj));
*** 372,382 ****
* object, or undefined if absent.
*/
public Object getOwnPropertyDescriptor(final String key) {
final Property property = getMap().findProperty(key);
! final GlobalObject global = (GlobalObject)Context.getGlobalTrusted();
if (property != null) {
final ScriptFunction get = property.getGetterFunction(this);
final ScriptFunction set = property.getSetterFunction(this);
--- 372,382 ----
* object, or undefined if absent.
*/
public Object getOwnPropertyDescriptor(final String key) {
final Property property = getMap().findProperty(key);
! final Global global = Context.getGlobal();
if (property != null) {
final ScriptFunction get = property.getGetterFunction(this);
final ScriptFunction set = property.getSetterFunction(this);
*** 437,447 ****
* @param reject is the property extensible - true means new definitions are rejected
*
* @return true if property was successfully defined
*/
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
! final ScriptObject global = Context.getGlobalTrusted();
final PropertyDescriptor desc = toPropertyDescriptor(global, propertyDesc);
final Object current = getOwnPropertyDescriptor(key);
final String name = JSType.toString(key);
if (current == UNDEFINED) {
--- 437,447 ----
* @param reject is the property extensible - true means new definitions are rejected
*
* @return true if property was successfully defined
*/
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
! final Global global = Context.getGlobal();
final PropertyDescriptor desc = toPropertyDescriptor(global, propertyDesc);
final Object current = getOwnPropertyDescriptor(key);
final String name = JSType.toString(key);
if (current == UNDEFINED) {
*** 635,645 ****
PropertyDescriptor pdesc = propertyDesc;
final int propFlags = Property.toFlags(pdesc);
if (pdesc.type() == PropertyDescriptor.GENERIC) {
! final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false);
dDesc.fillFrom((ScriptObject)pdesc);
pdesc = dDesc;
}
--- 635,645 ----
PropertyDescriptor pdesc = propertyDesc;
final int propFlags = Property.toFlags(pdesc);
if (pdesc.type() == PropertyDescriptor.GENERIC) {
! final Global global = Context.getGlobal();
final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false);
dDesc.fillFrom((ScriptObject)pdesc);
pdesc = dDesc;
}
*** 1148,1158 ****
}
p = p.getProto();
}
setProto((ScriptObject)newProto);
} else {
! final ScriptObject global = Context.getGlobalTrusted();
final Object newProtoObject = JSType.toScriptObject(global, newProto);
if (newProtoObject instanceof ScriptObject) {
setProto((ScriptObject)newProtoObject);
} else {
--- 1148,1158 ----
}
p = p.getProto();
}
setProto((ScriptObject)newProto);
} else {
! final Global global = Context.getGlobal();
final Object newProtoObject = JSType.toScriptObject(global, newProto);
if (newProtoObject instanceof ScriptObject) {
setProto((ScriptObject)newProtoObject);
} else {
*** 1238,1252 ****
*
* @param typeHint the preferred type hint
* @return the default value
*/
public Object getDefaultValue(final Class<?> typeHint) {
! // We delegate to GlobalObject, as the implementation uses dynamic call sites to invoke object's "toString" and
// "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
// are being executed in a long-running program, we move the code and their associated dynamic call sites
// (Global.TO_STRING and Global.VALUE_OF) into per-context code.
! return ((GlobalObject)Context.getGlobalTrusted()).getDefaultValue(this, typeHint);
}
/**
* Checking whether a script object is an instance of another. Used
* in {@link ScriptFunction} for hasInstance implementation, walks
--- 1238,1252 ----
*
* @param typeHint the preferred type hint
* @return the default value
*/
public Object getDefaultValue(final Class<?> typeHint) {
! // We delegate to Global, as the implementation uses dynamic call sites to invoke object's "toString" and
// "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
// are being executed in a long-running program, we move the code and their associated dynamic call sites
// (Global.TO_STRING and Global.VALUE_OF) into per-context code.
! return Context.getGlobal().getDefaultValue(this, typeHint);
}
/**
* Checking whether a script object is an instance of another. Used
* in {@link ScriptFunction} for hasInstance implementation, walks