jdk.nashorn.internal.runtime.Property Java Examples
The following examples show how to use
jdk.nashorn.internal.runtime.Property.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NashornGuards.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Get the guard for a property access. This returns an identity guard for non-configurable global properties * and a map guard for everything else. * * @param sobj the first object in the prototype chain * @param property the property * @param desc the callsite descriptor * @param explicitInstanceOfCheck true if we should do an explicit script object instanceof check instead of just casting * @return method handle for guard */ public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck) { if (!needsGuard(property, desc)) { return null; } if (NashornCallSiteDescriptor.isScope(desc) && sobj.isScope()) { if (property != null && property.isBound() && !property.canChangeType()) { // This is a declared top level variables in main script or eval, use identity guard. return getIdentityGuard(sobj); } if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) { // Undeclared variables in nested evals need stronger guards return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap(), explicitInstanceOfCheck)); } } return getMapGuard(sobj.getMap(), explicitInstanceOfCheck); }
Example #2
Source File: NativeStrictArguments.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #3
Source File: JSONParser.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #4
Source File: JSONParser.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #5
Source File: JSONParser.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #6
Source File: NativeStrictArguments.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #7
Source File: NashornGuards.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Get the guard for a property access. This returns an identity guard for non-configurable global properties * and a map guard for everything else. * * @param sobj the first object in the prototype chain * @param property the property * @param desc the callsite descriptor * @param explicitInstanceOfCheck true if we should do an explicit script object instanceof check instead of just casting * @return method handle for guard */ public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck) { if (!needsGuard(property, desc)) { return null; } if (NashornCallSiteDescriptor.isScope(desc)) { if (property != null && property.isBound() && !property.canChangeType()) { // This is a declared top level variables in main script or eval, use identity guard. return getIdentityGuard(sobj); } if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) { // Undeclared variables in nested evals need stronger guards return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap(), explicitInstanceOfCheck)); } } return getMapGuard(sobj.getMap(), explicitInstanceOfCheck); }
Example #8
Source File: NashornGuards.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * Get the guard for a property access. This returns an identity guard for non-configurable global properties * and a map guard for everything else. * * @param sobj the first object in the prototype chain * @param property the property * @param desc the callsite descriptor * @param explicitInstanceOfCheck true if we should do an explicit script object instanceof check instead of just casting * @return method handle for guard */ public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck) { if (!needsGuard(property, desc)) { return null; } if (NashornCallSiteDescriptor.isScope(desc)) { if (property != null && property.isBound() && !property.canChangeType()) { // This is a declared top level variables in main script or eval, use identity guard. return getIdentityGuard(sobj); } if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) { // Undeclared variables in nested evals need stronger guards return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap(), explicitInstanceOfCheck)); } } return getMapGuard(sobj.getMap(), explicitInstanceOfCheck); }
Example #9
Source File: JSONParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #10
Source File: NativeStrictArguments.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #11
Source File: JSONParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #12
Source File: JSONParser.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #13
Source File: MapCreator.java From nashorn with GNU General Public License v2.0 | 6 votes |
/** * Compute property flags given local state of a field. May be overridden and extended, * * @param symbol symbol to check * @param hasArguments does the created object have an "arguments" property * * @return flags to use for fields */ protected int getPropertyFlags(final Symbol symbol, final boolean hasArguments) { int flags = 0; if (symbol.isParam()) { flags |= Property.IS_ALWAYS_OBJECT | Property.IS_PARAMETER; } if (hasArguments) { flags |= Property.IS_ALWAYS_OBJECT | Property.HAS_ARGUMENTS; } if (symbol.isScope()) { flags |= Property.NOT_CONFIGURABLE; } if (symbol.canBePrimitive()) { flags |= Property.CAN_BE_PRIMITIVE; } if (symbol.canBeUndefined()) { flags |= Property.CAN_BE_UNDEFINED; } return flags; }
Example #14
Source File: JSONParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #15
Source File: NativeStrictArguments.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #16
Source File: NativeStrictArguments.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #17
Source File: JSONParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #18
Source File: JSONParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #19
Source File: JSONParser.java From hottub with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #20
Source File: JSONParser.java From hottub with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #21
Source File: NativeStrictArguments.java From hottub with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #22
Source File: NashornGuards.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Get the guard for a property access. This returns an identity guard for non-configurable global properties * and a map guard for everything else. * * @param sobj the first object in the prototype chain * @param property the property * @param desc the callsite descriptor * @param explicitInstanceOfCheck true if we should do an explicit script object instanceof check instead of just casting * @return method handle for guard */ public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck) { if (!needsGuard(property, desc)) { return null; } if (NashornCallSiteDescriptor.isScope(desc)) { if (property != null && property.isBound() && !property.canChangeType()) { // This is a declared top level variables in main script or eval, use identity guard. return getIdentityGuard(sobj); } if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) { // Undeclared variables in nested evals need stronger guards return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap(), explicitInstanceOfCheck)); } } return getMapGuard(sobj.getMap(), explicitInstanceOfCheck); }
Example #23
Source File: NativeStrictArguments.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) { super(proto, map); setIsArguments(); final ScriptFunction func = Global.instance().getTypeErrorThrower(); // We have to fill user accessor functions late as these are stored // in this object rather than in the PropertyMap of this object. final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; initUserAccessors("caller", flags, func, func); initUserAccessors("callee", flags, func, func); setArray(ArrayData.allocate(values)); this.length = values.length; // extend/truncate named arg array as needed and copy values this.namedArgs = new Object[numParams]; if (numParams > values.length) { Arrays.fill(namedArgs, UNDEFINED); } System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length)); }
Example #24
Source File: JSONParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) { final long[] primitiveSpill = dualFields ? new long[values.size()] : null; final Object[] objectSpill = new Object[values.size()]; for (final Property property : propertyMap.getProperties()) { if (!dualFields || property.getType() == Object.class) { objectSpill[property.getSlot()] = values.get(property.getSlot()); } else { primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot())); } } final ScriptObject object = dualFields ? new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill); object.setInitialProto(global.getObjectPrototype()); object.setArray(arrayData); return object; }
Example #25
Source File: JSONParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #26
Source File: JSONParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private PropertyMap addObjectProperty(final PropertyMap propertyMap, final List<Object> values, final String id, final Object value) { final Property oldProperty = propertyMap.findProperty(id); final PropertyMap newMap; final Class<?> type; final int flags; if (dualFields) { type = getType(value); flags = Property.DUAL_FIELDS; } else { type = Object.class; flags = 0; } if (oldProperty != null) { values.set(oldProperty.getSlot(), value); newMap = propertyMap.replaceProperty(oldProperty, new SpillProperty(id, flags, oldProperty.getSlot(), type));; } else { values.add(value); newMap = propertyMap.addProperty(new SpillProperty(id, flags, propertyMap.size(), type)); } return newMap; }
Example #27
Source File: NativeObject.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
/** * ECMA 15.2.4.7 Object.prototype.propertyIsEnumerable (V) * * @param self self reference * @param v property to check if enumerable * @return true if property is enumerable */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static boolean propertyIsEnumerable(final Object self, final Object v) { final String str = JSType.toString(v); final Object obj = Global.toObject(self); if (obj instanceof ScriptObject) { final jdk.nashorn.internal.runtime.Property property = ((ScriptObject)obj).getMap().findProperty(str); return property != null && property.isEnumerable(); } return false; }
Example #28
Source File: Shell.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Runs launches "fx:bootstrap.js" with the given JavaScript files provided * as arguments. * * @param context the nashorn context * @param global the global scope * @param files the list of script files to provide * * @return error code * @throws IOException when any script file read results in I/O error */ private static int runFXScripts(final Context context, final Global global, final List<String> files) throws IOException { final Global oldGlobal = Context.getGlobal(); final boolean globalChanged = (oldGlobal != global); try { if (globalChanged) { Context.setGlobal(global); } global.addOwnProperty("$GLOBAL", Property.NOT_ENUMERABLE, global); global.addOwnProperty("$SCRIPTS", Property.NOT_ENUMERABLE, files); context.load(global, "fx:bootstrap.js"); } catch (final NashornException e) { context.getErrorManager().error(e.toString()); if (context.getEnv()._dump_on_error) { e.printStackTrace(context.getErr()); } return RUNTIME_ERROR; } finally { context.getOut().flush(); context.getErr().flush(); if (globalChanged) { Context.setGlobal(oldGlobal); } } return SUCCESS; }
Example #29
Source File: Shell.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Runs launches "fx:bootstrap.js" with the given JavaScript files provided * as arguments. * * @param context the nashorn context * @param global the global scope * @param files the list of script files to provide * * @return error code * @throws IOException when any script file read results in I/O error */ private static int runFXScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { final ScriptObject oldGlobal = Context.getGlobal(); final boolean globalChanged = (oldGlobal != global); try { if (globalChanged) { Context.setGlobal(global); } global.addOwnProperty("$GLOBAL", Property.NOT_ENUMERABLE, global); global.addOwnProperty("$SCRIPTS", Property.NOT_ENUMERABLE, files); context.load(global, "fx:bootstrap.js"); } catch (final NashornException e) { context.getErrorManager().error(e.toString()); if (context.getEnv()._dump_on_error) { e.printStackTrace(context.getErr()); } return RUNTIME_ERROR; } finally { context.getOut().flush(); context.getErr().flush(); if (globalChanged) { Context.setGlobal(oldGlobal); } } return SUCCESS; }
Example #30
Source File: NashornScriptEngine.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private ScriptObject createNashornGlobal(final ScriptContext ctxt) { final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() { @Override public ScriptObject run() { try { return nashornContext.newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); nashornContext.initGlobal(newGlobal); final int NON_ENUMERABLE_CONSTANT = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE; // current ScriptContext exposed as "context" // "context" is non-writable from script - but script engine still // needs to set it and so save the context Property object contextProperty = newGlobal.addOwnProperty("context", NON_ENUMERABLE_CONSTANT, ctxt); // current ScriptEngine instance exposed as "engine". We added @SuppressWarnings("LeakingThisInConstructor") as // NetBeans identifies this assignment as such a leak - this is a false positive as we're setting this property // in the Global of a Context we just created - both the Context and the Global were just created and can not be // seen from another thread outside of this constructor. newGlobal.addOwnProperty("engine", NON_ENUMERABLE_CONSTANT, this); // global script arguments with undefined value newGlobal.addOwnProperty("arguments", Property.NOT_ENUMERABLE, UNDEFINED); // file name default is null newGlobal.addOwnProperty(ScriptEngine.FILENAME, Property.NOT_ENUMERABLE, null); // evaluate engine.js initialization script this new global object try { evalImpl(compileImpl(ENGINE_SCRIPT_SRC, newGlobal), ctxt, newGlobal); } catch (final ScriptException exp) { throw new RuntimeException(exp); } return newGlobal; }