@Override public Object apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toObject(res, scope) : null; } };
private static Scriptable getIntValue() { Value value = new Value(); value.setValue( 1 ); return Context.toObject( value, scope ); }
private static Scriptable getDoubleValue() { Value value = new Value(); value.setValue( 1.0 ); return Context.toObject( value, scope ); }
@Test public void jsToNumber_NativeNumber() throws Exception { Scriptable value = Context.toObject( 1.0, scope ); Number number = JavaScriptUtils.jsToNumber( value, NATIVE_NUMBER ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }
@Test public void jsToBigNumber_NativeNumber() throws Exception { Scriptable value = Context.toObject( 1.0, scope ); BigDecimal number = JavaScriptUtils.jsToBigNumber( value, NATIVE_NUMBER ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }
@Test public void jsToBigNumber_NativeJavaObject_BigDecimal() throws Exception { Value value = new Value(); value.setValue( BigDecimal.ONE ); Scriptable object = Context.toObject( value, scope ); assertEquals( 1.0, JavaScriptUtils.jsToBigNumber( object, JAVA_OBJECT ).doubleValue(), 1e-6 ); }
Scriptable jsR = Context.toObject( jsScripts[i].getScript(), jsscope ); jsscope.put( jsScripts[i].getScriptName(), jsscope, jsR ); Scriptable jsvalue = Context.toObject( dummyStep, jsscope ); jsscope.put( "_step_", jsscope, jsvalue ); Scriptable jsRowMeta = Context.toObject( prev, jsscope ); jsscope.put( "rowMeta", jsscope, jsRowMeta ); for ( int i = 0; i < prev.size(); i++ ) { Scriptable jsarg = Context.toObject( value, jsscope ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); } else { Scriptable jsarg = Context.toObject( valueData, jsscope ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); Scriptable jsval = Context.toObject( Value.class, jsscope ); jsscope.put( "Value", jsscope, jsval ); Scriptable jsV2Row = Context.toObject( v2Row, jsscope ); jsscope.put( "row", jsscope, jsV2Row ); } else { Scriptable jsRow = Context.toObject( row, jsscope ); jsscope.put( "row", jsscope, jsRow );
Scriptable jsR = Context.toObject( sItem.getText(), jsscope ); jsscope.put( folder.getItem( i ).getText(), jsscope, jsR ); Scriptable jsvalue = Context.toObject( dummyStep, jsscope ); jsscope.put( "_step_", jsscope, jsvalue ); Scriptable jsRowMeta = Context.toObject( rowMeta, jsscope ); jsscope.put( "rowMeta", jsscope, jsRowMeta ); for ( int i = 0; i < rowMeta.size(); i++ ) { Scriptable jsarg = Context.toObject( value, jsscope ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); } else { Scriptable jsarg = Context.toObject( valueData, jsscope ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); Scriptable jsval = Context.toObject( Value.class, jsscope ); jsscope.put( "Value", jsscope, jsval ); Scriptable jsV2Row = Context.toObject( v2Row, jsscope ); jsscope.put( "row", jsscope, jsV2Row ); } else { Scriptable jsRow = Context.toObject( row, jsscope ); jsscope.put( "row", jsscope, jsRow );
Scriptable jsR = Context.toObject( sItem.getText(), jsscope ); jsscope.put( folder.getItem( i ).getText(), jsscope, jsR ); Scriptable jsvalue = Context.toObject( dummyStep, jsscope ); jsscope.put( "_step_", jsscope, jsvalue ); Scriptable jsRowMeta = Context.toObject( rowMeta, jsscope ); jsscope.put( "rowMeta", jsscope, jsRowMeta ); for ( int i = 0; i < rowMeta.size(); i++ ) { Scriptable jsarg = Context.toObject( valueData, jsscope ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); Scriptable jsval = Context.toObject( Value.class, jsscope ); jsscope.put( "Value", jsscope, jsval ); Scriptable jsRow = Context.toObject( row, jsscope ); jsscope.put( "row", jsscope, jsRow );
Scriptable jsvalue = Context.toObject( this, data.scope ); data.scope.put( "_step_", data.scope, jsvalue ); Scriptable jsR = Context.toObject( jsScripts[ i ].getScript(), data.scope ); data.scope.put( jsScripts[ i ].getScriptName(), data.scope, jsR ); Scriptable jsV2Row = Context.toObject( v2Row, data.scope ); data.scope.put( "row", data.scope, jsV2Row ); } else { Scriptable jsrow = Context.toObject( row, data.scope ); data.scope.put( "row", data.scope, jsrow ); Scriptable jsarg = Context.toObject( data.values_used[ i ], data.scope ); data.scope.put( valueMeta.getName(), data.scope, jsarg ); } else { Scriptable jsarg; if ( normalStorageValueData != null ) { jsarg = Context.toObject( normalStorageValueData, data.scope ); } else { jsarg = null; Scriptable jsrowMeta = Context.toObject( rowMeta, data.scope ); data.scope.put( "rowMeta", data.scope, jsrowMeta ); if ( meta.isCompatible() ) { Row v2Row = RowMeta.createOriginalRow( rowMeta, row ); Scriptable jsV2Row = Context.toObject( v2Row, data.scope ); data.scope.put( "row", data.scope, jsV2Row );
private Object toJS(Object value) { return value == null || (value instanceof Number) || (value instanceof String) || (value instanceof Boolean) ? value: Context.toObject(value, _global); } protected void unset(String name) {
public Object run(Context cx) { Object a = Context.toObject(arg, globalObject); Object[] args = { a }; handler.call(cx, globalObject, globalObject, args); return null; } });
public Scriptable getLog() { if (log != null) { return log; } log = org.mozilla.javascript.Context.toObject(getLogger(), getParentScope()); return log; }
public void declareBean(BSFDeclaredBean bean) throws BSFException { // Must wrap non-scriptable objects before presenting to Rhino Scriptable wrapped = Context.toObject(bean.bean, global); global.put(bean.name, global, wrapped); }
public Object run(Context cx) { Object a = Context.toObject(arg, globalObject); Object[] args = { a }; handler.call(cx, globalObject, globalObject, args); return null; } });
/** * Get the current settings object for java script. */ public Scriptable jsGet_settings() { final Settings s = this.getSettings(); return org.mozilla.javascript.Context.toObject(s, getParentScope()); }
/** * Get the current application context for java script. */ public Scriptable jsGet_applicationContext() { final WebApplicationContext w = this.getApplicationContext(); return org.mozilla.javascript.Context.toObject(w, getParentScope()); }
@Override public Object apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toObject(res, scope) : null; } };
public Scriptable getResponse() { if (response != null) { return response; } response = org.mozilla.javascript.Context.toObject( ObjectModelHelper.getResponse(this.getObjectModel()), getParentScope()); return response; }
public Scriptable getScriptable(UserContext userContext) { Map<String, Scriptable> scopes = threadLocalScope.get(); String mapKey = userContext.locale.toString() + userContext.timeZone; Scriptable scope = scopes.get(mapKey); if (scope == null) { scope = setupContext(getOntologyJson(userContext.getWorkspaceId()), getConfigurationJson(userContext.locale, userContext.getWorkspaceId()), userContext.timeZone); scopes.put(mapKey, scope); } else { scope.put("ONTOLOGY_JSON", scope, Context.toObject(getOntologyJson(userContext.getWorkspaceId()), scope)); } return scope; }