Fixes and improvements to JS APIs

This commit is contained in:
Alexey Andreev 2019-02-08 12:45:39 +03:00
parent bc41b12f0e
commit 5c90d786a0
5 changed files with 15 additions and 33 deletions

View File

@ -1,30 +0,0 @@
/*
* Copyright 2019 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.jso.core;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
public final class JSON {
private JSON() {
}
@JSBody(params = "s", script = "return JSON.parse(s);")
public static native <T extends JSObject> T parse(String s);
@JSBody(params = "o", script = "JSON.stringify(o);")
public static native String stringify(JSObject o);
}

View File

@ -25,12 +25,18 @@ public final class JSObjects {
@JSBody(params = "object", script = "return Object.getOwnPropertyNames(object);")
public static native String[] getOwnPropertyNames(JSObject object);
@JSBody(script = "return Object.create(null);")
@JSBody(script = "return {};")
public static native <T extends JSObject> T create();
@JSBody(script = "return Object.create(null);")
public static native <T extends JSObject> T createWithoutProto();
@JSBody(params = "object", script = "return typeof object === 'undefined';")
public static native boolean isUndefined(JSObject object);
@JSBody(script = "return void 0;")
public static native JSObject undefined();
@JSBody(params = "object", script = "return typeof object;")
public static native String typeOf(JSObject object);

View File

@ -88,4 +88,6 @@ public interface HTMLDocument extends Document, EventTarget {
@JSProperty
HTMLElement getPointerLockElement();
void exitPointerLock();
}

View File

@ -188,6 +188,4 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget
NodeList<? extends HTMLElement> querySelectorAll(String selectors);
void requestPointerLock();
void exitPointerLock();
}

View File

@ -48,4 +48,10 @@ public interface HTMLImageElement extends HTMLElement, CanvasImageSource {
@JSProperty
void setSrc(String src);
@JSProperty
String getCrossOrigin();
@JSProperty
void setCrossOrigin(String crossOrigin);
}