blob: 3668af082a8bab8ad4bd4fe6433d843e72d45399 [file]
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
*
*/
package org.mozilla.javascript.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
/**
* @author Ronald Brill
*/
public class NativeJsonTest {
@Test
public void stringifyResultAndResultType() {
String jsScript = "function f(){ return JSON.stringify({property1:\"hello\", array1:[{subobject:1}]}); } f();";
Context jsContext = Context.enter();
try {
Scriptable jsScope= jsContext.initStandardObjects();
Object result = jsContext.evaluateString(jsScope, jsScript, "myscript.js", 1, null);
assertEquals("{\"property1\":\"hello\",\"array1\":[{\"subobject\":1}]}", result);
assertEquals("java.lang.String", result.getClass().getName());
} finally {
Context.exit();
}
}
}