EcmaScriptDataModel implements DataModel { @Override public int createScope(final Scope scope) { if (scope == null) { return createScope(); } if (topmostScope == null) { final Context context = getContext(); rootScope = context.initStandardObjects(); topmostScope = rootScope; } final Context context = Context.getCurrentContext(); final Scriptable newScope = context.newObject(topmostScope); newScope.setPrototype(topmostScope); newScope.setParentScope(null); if (scope != Scope.ANONYMOUS) { ScriptableObject.putProperty(newScope, scope.getName(), newScope); } topmostScope = newScope; scopes.put(topmostScope, scope); if (LOGGER.isDebugEnabled()) { LOGGER.debug("created scope '" + scope.name() + "'"); } return NO_ERROR; } EcmaScriptDataModel(); @Override DataModel newInstance(); @Override Object getUndefinedValue(); @Override Object createNewObject(); @Override int createScope(final Scope scope); @Override int copyValues(final DataModel model); @Override int createScope(); @Override int deleteScope(); @Override int deleteScope(final Scope scope); @Override int createVariable(final String variableName); @Override int createVariable(final String variableName, final Object value); @Override int createVariable(final String variableName, final Object value,
            final Scope scope); @Override int createVariableFor(final Object variable,
            final String variableName); @Override int createVariableFor(Object variable, final String variableName,
            final Object value); @Override int createArray(String arrayName, int dimension); @Override int createArray(final String arrayName, final int dimension,
            final Scope scope); @Override int resizeArray(final String arrayName, final int dimension); @Override int resizeArray(final String arrayName, final int dimension,
            final Scope scope); @Override boolean existsVariable(final String variableName); @Override boolean existsVariable(final String variableName, final Scope scope); boolean existsVariable(final String variableName, final Scope scope,
            final Scriptable start); @Override int deleteVariable(final String variableName); @Override int deleteVariable(final String variableName, final Scope scope); @Override int updateVariable(final String variableName, final Object newValue); @Override int updateVariable(final String variableName, final Object newValue,
            final Scope scope); @Override int updateVariableFor(final Object variable,
            final String variableName, final Object newValue); @Override int updateArray(final String variableName, final int position,
            final Object newValue); @Override int updateArray(final String variableName, final int position,
            final Object newValue, final Scope scope); @Override T readVariable(final String variableName,
            final Class<T> type); @Override T readVariable(String variableName, Scope scope,
            final Class<T> type); @Override T readArray(final String arrayName, final int position,
            final Class<T> type); @Override T readArray(final String arrayName, final int position,
            final Scope scope, final Class<T> type); @Override T evaluateExpression(final String expr,
            final Class<T> type); @Override T evaluateExpression(final String expr,
            final Scope scope, final Class<T> type); @Override String toString(final Object object); static String toJSON(final Scriptable object); void setSerializer(final DataModelObjectSerializer value); @Override DataModelObjectSerializer getSerializer();  }
@Test public void testCreateScopeScope() { final DataModel data = new EcmaScriptDataModel(); Assert.assertEquals(DataModel.NO_ERROR, data.createScope(Scope.SESSION)); Assert.assertEquals(DataModel.NO_ERROR, data.createScope(Scope.APPLICATION)); }
@Test public void testCreateScopeNullScope() { final DataModel data = new EcmaScriptDataModel(); Assert.assertEquals(DataModel.NO_ERROR, data.createScope(null)); Assert.assertEquals(DataModel.NO_ERROR, data.createScope(null)); }
@Test public void testCreateScope() { final DataModel data = new EcmaScriptDataModel(); Assert.assertEquals(DataModel.NO_ERROR, data.createScope()); Assert.assertEquals(DataModel.NO_ERROR, data.createScope()); }