Example usage for jdk.nashorn.internal.runtime Undefined getUndefined

List of usage examples for jdk.nashorn.internal.runtime Undefined getUndefined

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime Undefined getUndefined.

Prototype

public static Undefined getUndefined() 

Source Link

Document

Get the value of undefined , this is represented as a global singleton instance of this class.

Usage

From source file:com.mckoi.mwpui.nodejs.nashorn.NashornJSSystem.java

License:Open Source License

@Override
public ByteBuffer getExternalArrayDataOf(GJSObject source) {

    ScriptObjectMirror nashorn_ob = (ScriptObjectMirror) source.internalGetNative();
    // We use the unwrapped nashorn object as a key,
    ScriptObject script_ob = (ScriptObject) instance_global.unwrap(nashorn_ob);

    Object value = script_ob.get(BYTEBUFFER_OBJECT_PROPERTY_NAME);
    if (value == null || Undefined.getUndefined().equals(value)) {
        return null;
    }/*w w  w  .  j  a va  2s.  c  om*/
    return (ByteBuffer) value;

}

From source file:com.mckoi.mwpui.nodejs.nashorn.NashornJSSystem.java

License:Open Source License

/**
 * Wraps the given Nashorn Object as a GJSObject.
 * //from w  w  w . j  a  v a 2 s . c o m
 * @param js_object
 * @return 
 */
final Object wrapAsGJS(Object nashorn_value) {
    if (nashorn_value == null) {
        return null;
    } else if (nashorn_value == Undefined.getUndefined() || nashorn_value == Undefined.getEmpty()) {
        return GJSStatics.UNDEFINED;
    } else if (nashorn_value instanceof CharSequence) {
        return nashorn_value.toString();
    } else if (nashorn_value instanceof Number || nashorn_value instanceof Boolean) {
        return nashorn_value;
    }
    // Wrap ScriptObject,
    if (nashorn_value instanceof ScriptObject) {
        nashorn_value = instance_global.wrap((ScriptObject) nashorn_value);
    }
    if (nashorn_value instanceof JSObject) {
        JSObject nashorn_object = (JSObject) nashorn_value;
        GJSObject gjs_ob = getGJSFromNative(nashorn_object);
        if (gjs_ob == null) {
            gjs_ob = new NashornGJSObjectWrap(this, nashorn_object);
        }
        return gjs_ob;
    } else if (nashorn_value instanceof NashornException) {
        return wrappedGJSException((NashornException) nashorn_value);
    } else {
        return nashorn_value;
        //      throw new GJavaScriptException("Unable to convert Nashorn value: " +
        //                                                  (nashorn_value.getClass()));
    }

}

From source file:com.mckoi.mwpui.nodejs.nashorn.NashornJSSystem.java

License:Open Source License

final Object wrapAsNashorn(Object gvalue) {
    if (gvalue == null) {
        return null;
    } else if (GJSStatics.UNDEFINED.equals(gvalue)) {
        return Undefined.getUndefined();
    } else if (gvalue instanceof CharSequence) {
        return gvalue;
    } else if (gvalue instanceof Number || gvalue instanceof Boolean) {
        return gvalue;
    } else if (gvalue instanceof GJSObject) {
        GJSObject gjs_object = (GJSObject) gvalue;
        // Convert to nashorn object,
        JSObject nashorn_ob = (JSObject) gjs_object.internalGetNative();
        if (nashorn_ob == null) {
            nashorn_ob = convertGJSToNashorn(gjs_object);
            gjs_object.internalSetNative(nashorn_ob);
        }//from  w w w  .j a  v  a2s . c  om
        return instance_global.unwrap(nashorn_ob);
    } else if (gvalue instanceof GJavaScriptException) {
        NashornException ex = wrappedNashornException((GJavaScriptException) gvalue);
        return ex;
    } else {
        return gvalue;
        //      throw new GJavaScriptException(
        //                  "Unable to convert GJS object: " + gvalue.getClass());
    }

}

From source file:net.desertconsulting.mocharest.RestEngineImplTest.java

License:Apache License

@Test
public void testHandlePostJsonHandlerReturnsUndefined() throws MalformedURLException {
    System.out.println("handlePostJsonHandlerReturnsUndefined");
    String testUrl = "/test/{test:int}";
    final String testBody = "{\"test\":\"test\"}";
    HttpServletRequest request = MockedRequest.create().withMethod(RestEngine.POST_METHOD)
            .withTestBody(testBody).withMimeType(MediaType.APPLICATION_JSON).withPath("/test/1").build()
            .getMockInstance();/* w w w .  j av  a2 s  . c  om*/
    MockedResponse sr = getTestHandleResponse();
    RestEngineImpl instance = new RestEngineImpl(context);
    JSObject parm = new MockUp<JSObject>() {
        @Mock
        public boolean isFunction() {
            return true;
        }

        @Mock
        public Object call(Object o, Object... os) {
            if (os[0] instanceof MochaRequest && os[0] != null) {
                Object body = ((MochaRequest) os[0]).getBody();
                if (os[1] instanceof MochaResponse && os[1] != null) {
                    if (os[2] instanceof Map && os[2] != null) {
                        if (os[3] instanceof Map && os[3] != null) {
                            if ((int) ((Map<String, Object>) os[3]).get("test") == 1) {
                                return Undefined.getUndefined();
                            } else {
                                throw new IllegalArgumentException("request.PathParameters['test']");
                            }
                        } else {
                            throw new IllegalArgumentException("request.PathParameters");
                        }
                    } else {
                        throw new IllegalArgumentException("request.Parameters");
                    }
                } else {
                    throw new IllegalArgumentException("response");
                }
            } else {
                throw new IllegalArgumentException("request");
            }
        }
    }.getMockInstance();
    instance.post(testUrl, parm);
    HttpServletResponse response = sr.getMockInstance();
    instance.handle(request, response);
    String result = new String(sr.bos.toByteArray());
    assertEquals("", result);
    assertEquals(response.getContentType(), MediaType.APPLICATION_JSON);
}

From source file:org.bson.jvm.nashorn.UndefinedCodec.java

License:Apache License

public Undefined decode(BsonReader reader, DecoderContext decoderContext) {
    reader.readUndefined();
    return Undefined.getUndefined();
}

From source file:reactor.js.test.RequireFunction.java

License:Open Source License

@Override
public Object getMember(String name) {
    return properties.containsKey(name) ? properties.get(name) : Undefined.getUndefined();
}