From 6366f966b760c0640a47175f7cf749c7713be66f Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 7 May 2015 21:26:03 +0300 Subject: [PATCH] JS Introduce typed arrays --- js/js.libraries/src/core/domUtils.kt | 12 - .../src/generated/org.khronos.webgl.kt | 313 ++++++++++++++++-- js/js.libraries/src/generated/org.w3c.dom.kt | 11 +- .../src/generated/org.w3c.files.kt | 2 +- js/js.libraries/src/generated/org.w3c.xhr.kt | 6 +- js/js.libraries/src/html5/storage.kt | 4 +- libraries/idl/org.khronos.webgl.idl | 287 ++++++++++++++++ libraries/idl/org.w3c.xhr.idl | 8 +- .../main/antlr4/org/antlr/webidl/WebIDL.g4 | 15 - .../tools/idl2k/src/main/kotlin/download.kt | 3 +- .../idl2k/src/main/kotlin/typeMappings.kt | 6 +- 11 files changed, 593 insertions(+), 74 deletions(-) diff --git a/js/js.libraries/src/core/domUtils.kt b/js/js.libraries/src/core/domUtils.kt index 8831808283d..a4e1f91507a 100644 --- a/js/js.libraries/src/core/domUtils.kt +++ b/js/js.libraries/src/core/domUtils.kt @@ -19,18 +19,6 @@ package org.w3c.dom import java.util.AbstractList import kotlin.js.splitWithRegex -native -public val window: Window = noImpl - -native -public val document: Document = noImpl - -native -public val localStorage: Storage = noImpl - -native -public val sessionStorage: Storage = noImpl - private class HTMLCollectionListView(val collection: HTMLCollection) : AbstractList() { override fun size(): Int = collection.length diff --git a/js/js.libraries/src/generated/org.khronos.webgl.kt b/js/js.libraries/src/generated/org.khronos.webgl.kt index 1060184057f..d2a8fc06df9 100644 --- a/js/js.libraries/src/generated/org.khronos.webgl.kt +++ b/js/js.libraries/src/generated/org.khronos.webgl.kt @@ -97,7 +97,7 @@ native public trait WebGLRenderingContext { fun bindFramebuffer(target: Int, framebuffer: WebGLFramebuffer?): Unit = noImpl fun bindRenderbuffer(target: Int, renderbuffer: WebGLRenderbuffer?): Unit = noImpl fun bindTexture(target: Int, texture: WebGLTexture?): Unit = noImpl - fun blendColor(red: dynamic, green: dynamic, blue: dynamic, alpha: dynamic): Unit = noImpl + fun blendColor(red: Float, green: Float, blue: Float, alpha: Float): Unit = noImpl fun blendEquation(mode: Int): Unit = noImpl fun blendEquationSeparate(modeRGB: Int, modeAlpha: Int): Unit = noImpl fun blendFunc(sfactor: Int, dfactor: Int): Unit = noImpl @@ -107,8 +107,8 @@ native public trait WebGLRenderingContext { fun bufferSubData(target: Int, offset: Long, data: dynamic): Unit = noImpl fun checkFramebufferStatus(target: Int): Int = noImpl fun clear(mask: Int): Unit = noImpl - fun clearColor(red: dynamic, green: dynamic, blue: dynamic, alpha: dynamic): Unit = noImpl - fun clearDepth(depth: dynamic): Unit = noImpl + fun clearColor(red: Float, green: Float, blue: Float, alpha: Float): Unit = noImpl + fun clearDepth(depth: Float): Unit = noImpl fun clearStencil(s: Int): Unit = noImpl fun colorMask(red: Boolean, green: Boolean, blue: Boolean, alpha: Boolean): Unit = noImpl fun compileShader(shader: WebGLShader?): Unit = noImpl @@ -131,7 +131,7 @@ native public trait WebGLRenderingContext { fun deleteTexture(texture: WebGLTexture?): Unit = noImpl fun depthFunc(func: Int): Unit = noImpl fun depthMask(flag: Boolean): Unit = noImpl - fun depthRange(zNear: dynamic, zFar: dynamic): Unit = noImpl + fun depthRange(zNear: Float, zFar: Float): Unit = noImpl fun detachShader(program: WebGLProgram?, shader: WebGLShader?): Unit = noImpl fun disable(cap: Int): Unit = noImpl fun disableVertexAttribArray(index: Int): Unit = noImpl @@ -173,13 +173,13 @@ native public trait WebGLRenderingContext { fun isRenderbuffer(renderbuffer: WebGLRenderbuffer?): Boolean = noImpl fun isShader(shader: WebGLShader?): Boolean = noImpl fun isTexture(texture: WebGLTexture?): Boolean = noImpl - fun lineWidth(width: dynamic): Unit = noImpl + fun lineWidth(width: Float): Unit = noImpl fun linkProgram(program: WebGLProgram?): Unit = noImpl fun pixelStorei(pname: Int, param: Int): Unit = noImpl - fun polygonOffset(factor: dynamic, units: dynamic): Unit = noImpl + fun polygonOffset(factor: Float, units: Float): Unit = noImpl fun readPixels(x: Int, y: Int, width: Int, height: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl fun renderbufferStorage(target: Int, internalformat: Int, width: Int, height: Int): Unit = noImpl - fun sampleCoverage(value: dynamic, invert: Boolean): Unit = noImpl + fun sampleCoverage(value: Float, invert: Boolean): Unit = noImpl fun scissor(x: Int, y: Int, width: Int, height: Int): Unit = noImpl fun shaderSource(shader: WebGLShader?, source: String): Unit = noImpl fun stencilFunc(func: Int, ref: Int, mask: Int): Unit = noImpl @@ -190,53 +190,53 @@ native public trait WebGLRenderingContext { fun stencilOpSeparate(face: Int, fail: Int, zfail: Int, zpass: Int): Unit = noImpl fun texImage2D(target: Int, level: Int, internalformat: Int, width: Int, height: Int, border: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl fun texImage2D(target: Int, level: Int, internalformat: Int, format: Int, type: Int, source: dynamic): Unit = noImpl - fun texParameterf(target: Int, pname: Int, param: dynamic): Unit = noImpl + fun texParameterf(target: Int, pname: Int, param: Float): Unit = noImpl fun texParameteri(target: Int, pname: Int, param: Int): Unit = noImpl fun texSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, width: Int, height: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl fun texSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, format: Int, type: Int, source: dynamic): Unit = noImpl - fun uniform1f(location: WebGLUniformLocation?, x: dynamic): Unit = noImpl - fun uniform1fv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform1f(location: WebGLUniformLocation?, x: Float): Unit = noImpl + fun uniform1fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl fun uniform1fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl fun uniform1i(location: WebGLUniformLocation?, x: Int): Unit = noImpl - fun uniform1iv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform1iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl fun uniform1iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl - fun uniform2f(location: WebGLUniformLocation?, x: dynamic, y: dynamic): Unit = noImpl - fun uniform2fv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform2f(location: WebGLUniformLocation?, x: Float, y: Float): Unit = noImpl + fun uniform2fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl fun uniform2fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl fun uniform2i(location: WebGLUniformLocation?, x: Int, y: Int): Unit = noImpl - fun uniform2iv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform2iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl fun uniform2iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl - fun uniform3f(location: WebGLUniformLocation?, x: dynamic, y: dynamic, z: dynamic): Unit = noImpl - fun uniform3fv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform3f(location: WebGLUniformLocation?, x: Float, y: Float, z: Float): Unit = noImpl + fun uniform3fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl fun uniform3fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl fun uniform3i(location: WebGLUniformLocation?, x: Int, y: Int, z: Int): Unit = noImpl - fun uniform3iv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform3iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl fun uniform3iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl - fun uniform4f(location: WebGLUniformLocation?, x: dynamic, y: dynamic, z: dynamic, w: dynamic): Unit = noImpl - fun uniform4fv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform4f(location: WebGLUniformLocation?, x: Float, y: Float, z: Float, w: Float): Unit = noImpl + fun uniform4fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl fun uniform4fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl fun uniform4i(location: WebGLUniformLocation?, x: Int, y: Int, z: Int, w: Int): Unit = noImpl - fun uniform4iv(location: WebGLUniformLocation?, v: dynamic): Unit = noImpl + fun uniform4iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl fun uniform4iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl - fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: dynamic): Unit = noImpl + fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl - fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: dynamic): Unit = noImpl + fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl - fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: dynamic): Unit = noImpl + fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl fun useProgram(program: WebGLProgram?): Unit = noImpl fun validateProgram(program: WebGLProgram?): Unit = noImpl - fun vertexAttrib1f(indx: Int, x: dynamic): Unit = noImpl - fun vertexAttrib1fv(indx: Int, values: dynamic): Unit = noImpl + fun vertexAttrib1f(indx: Int, x: Float): Unit = noImpl + fun vertexAttrib1fv(indx: Int, values: Float32Array): Unit = noImpl fun vertexAttrib1fv(indx: Int, values: Any): Unit = noImpl - fun vertexAttrib2f(indx: Int, x: dynamic, y: dynamic): Unit = noImpl - fun vertexAttrib2fv(indx: Int, values: dynamic): Unit = noImpl + fun vertexAttrib2f(indx: Int, x: Float, y: Float): Unit = noImpl + fun vertexAttrib2fv(indx: Int, values: Float32Array): Unit = noImpl fun vertexAttrib2fv(indx: Int, values: Any): Unit = noImpl - fun vertexAttrib3f(indx: Int, x: dynamic, y: dynamic, z: dynamic): Unit = noImpl - fun vertexAttrib3fv(indx: Int, values: dynamic): Unit = noImpl + fun vertexAttrib3f(indx: Int, x: Float, y: Float, z: Float): Unit = noImpl + fun vertexAttrib3fv(indx: Int, values: Float32Array): Unit = noImpl fun vertexAttrib3fv(indx: Int, values: Any): Unit = noImpl - fun vertexAttrib4f(indx: Int, x: dynamic, y: dynamic, z: dynamic, w: dynamic): Unit = noImpl - fun vertexAttrib4fv(indx: Int, values: dynamic): Unit = noImpl + fun vertexAttrib4f(indx: Int, x: Float, y: Float, z: Float, w: Float): Unit = noImpl + fun vertexAttrib4fv(indx: Int, values: Float32Array): Unit = noImpl fun vertexAttrib4fv(indx: Int, values: Any): Unit = noImpl fun vertexAttribPointer(indx: Int, size: Int, type: Int, normalized: Boolean, stride: Int, offset: Long): Unit = noImpl fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = noImpl @@ -552,3 +552,254 @@ native public open class WebGLContextEventInit : EventInit() { var statusMessage: String } +native public open class ArrayBuffer(length: Int) { + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun slice(begin: Int, end: Int = noImpl): ArrayBuffer = noImpl +} + +native public open class Int8Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Byte = noImpl + fun set(index: Int, value: Byte): Unit = noImpl + fun set(array: Int8Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Int8Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 1 + } +} + +native public open class Uint8Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Byte = noImpl + fun set(index: Int, value: Byte): Unit = noImpl + fun set(array: Uint8Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Uint8Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 1 + } +} + +native public open class Uint8ClampedArray(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Byte = noImpl + fun set(index: Int, value: Byte): Unit = noImpl + fun set(array: Uint8ClampedArray, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Uint8ClampedArray = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 1 + } +} + +native public open class Int16Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Short = noImpl + fun set(index: Int, value: Short): Unit = noImpl + fun set(array: Int16Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Int16Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 2 + } +} + +native public open class Uint16Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Short = noImpl + fun set(index: Int, value: Short): Unit = noImpl + fun set(array: Uint16Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Uint16Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 2 + } +} + +native public open class Int32Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Int = noImpl + fun set(index: Int, value: Int): Unit = noImpl + fun set(array: Int32Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Int32Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 4 + } +} + +native public open class Uint32Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Int = noImpl + fun set(index: Int, value: Int): Unit = noImpl + fun set(array: Uint32Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Uint32Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 4 + } +} + +native public open class Float32Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Float = noImpl + fun set(index: Int, value: Float): Unit = noImpl + fun set(array: Float32Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Float32Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 4 + } +} + +native public open class Float64Array(length: Int) { + var length: Int + get() = noImpl + set(value) = noImpl + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun get(index: Int): Double = noImpl + fun set(index: Int, value: Double): Unit = noImpl + fun set(array: Float64Array, offset: Int = noImpl): Unit = noImpl + fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl + fun subarray(start: Int, end: Int): Float64Array = noImpl + + companion object { + val BYTES_PER_ELEMENT: Int = 8 + } +} + +native public open class DataView(buffer: ArrayBuffer, byteOffset: Int = noImpl, byteLength: Int = noImpl) { + var buffer: ArrayBuffer + get() = noImpl + set(value) = noImpl + var byteOffset: Int + get() = noImpl + set(value) = noImpl + var byteLength: Int + get() = noImpl + set(value) = noImpl + fun getInt8(byteOffset: Int): Byte = noImpl + fun getUint8(byteOffset: Int): Byte = noImpl + fun getInt16(byteOffset: Int, littleEndian: Boolean = noImpl): Short = noImpl + fun getUint16(byteOffset: Int, littleEndian: Boolean = noImpl): Short = noImpl + fun getInt32(byteOffset: Int, littleEndian: Boolean = noImpl): Int = noImpl + fun getUint32(byteOffset: Int, littleEndian: Boolean = noImpl): Int = noImpl + fun getFloat32(byteOffset: Int, littleEndian: Boolean = noImpl): Float = noImpl + fun getFloat64(byteOffset: Int, littleEndian: Boolean = noImpl): Double = noImpl + fun setInt8(byteOffset: Int, value: Byte): Unit = noImpl + fun setUint8(byteOffset: Int, value: Byte): Unit = noImpl + fun setInt16(byteOffset: Int, value: Short, littleEndian: Boolean = noImpl): Unit = noImpl + fun setUint16(byteOffset: Int, value: Short, littleEndian: Boolean = noImpl): Unit = noImpl + fun setInt32(byteOffset: Int, value: Int, littleEndian: Boolean = noImpl): Unit = noImpl + fun setUint32(byteOffset: Int, value: Int, littleEndian: Boolean = noImpl): Unit = noImpl + fun setFloat32(byteOffset: Int, value: Float, littleEndian: Boolean = noImpl): Unit = noImpl + fun setFloat64(byteOffset: Int, value: Double, littleEndian: Boolean = noImpl): Unit = noImpl +} + diff --git a/js/js.libraries/src/generated/org.w3c.dom.kt b/js/js.libraries/src/generated/org.w3c.dom.kt index a049059fd18..228c2f4c979 100644 --- a/js/js.libraries/src/generated/org.w3c.dom.kt +++ b/js/js.libraries/src/generated/org.w3c.dom.kt @@ -2907,7 +2907,7 @@ native public open class ImageData(sw: Int, sh: Int) { var height: Int get() = noImpl set(value) = noImpl - var data: dynamic + var data: Uint8ClampedArray get() = noImpl set(value) = noImpl } @@ -3731,7 +3731,8 @@ native public open class WebSocket(url: String, protocols: dynamic = noImpl) : E fun close(code: Short = noImpl, reason: String = noImpl): Unit = noImpl fun send(data: String): Unit = noImpl fun send(data: Blob): Unit = noImpl - fun send(data: dynamic): Unit = noImpl + fun send(data: ArrayBuffer): Unit = noImpl + fun send(data: ArrayBufferView): Unit = noImpl companion object { val CONNECTING: Short = 0 @@ -4854,6 +4855,12 @@ native public marker trait UnionElementOrMouseEvent { native public marker trait UnionElementOrProcessingInstruction { } +native public marker trait ArrayBufferView { +} + +native public marker trait Transferable { +} + native public marker trait RenderingContext { } diff --git a/js/js.libraries/src/generated/org.w3c.files.kt b/js/js.libraries/src/generated/org.w3c.files.kt index b17e97b3c5b..7a13b3635d6 100644 --- a/js/js.libraries/src/generated/org.w3c.files.kt +++ b/js/js.libraries/src/generated/org.w3c.files.kt @@ -98,7 +98,7 @@ native public open class FileReader : EventTarget { } native public open class FileReaderSync { - fun readAsArrayBuffer(blob: Blob): dynamic = noImpl + fun readAsArrayBuffer(blob: Blob): ArrayBuffer = noImpl fun readAsText(blob: Blob, label: String = noImpl): String = noImpl fun readAsDataURL(blob: Blob): String = noImpl } diff --git a/js/js.libraries/src/generated/org.w3c.xhr.kt b/js/js.libraries/src/generated/org.w3c.xhr.kt index 6e5721c3f65..7b3c58bbb94 100644 --- a/js/js.libraries/src/generated/org.w3c.xhr.kt +++ b/js/js.libraries/src/generated/org.w3c.xhr.kt @@ -100,14 +100,12 @@ native public open class XMLHttpRequest : XMLHttpRequestEventTarget { } native public open class FormData(form: HTMLFormElement = noImpl) { - fun append(name: String, value: Blob, filename: String = noImpl): Unit = noImpl - fun append(name: String, value: String): Unit = noImpl + fun append(name: String, value: dynamic): Unit = noImpl fun delete(name: String): Unit = noImpl fun get(name: String): dynamic = noImpl fun getAll(name: String): Any = noImpl fun has(name: String): Boolean = noImpl - fun set(name: String, value: Blob, filename: String = noImpl): Unit = noImpl - fun set(name: String, value: String): Unit = noImpl + fun set(name: String, value: dynamic): Unit = noImpl } native public open class ProgressEvent(type: String, eventInitDict: ProgressEventInit = noImpl) : Event(type, eventInitDict) { diff --git a/js/js.libraries/src/html5/storage.kt b/js/js.libraries/src/html5/storage.kt index cfb54e7c4de..dfd752a8f84 100644 --- a/js/js.libraries/src/html5/storage.kt +++ b/js/js.libraries/src/html5/storage.kt @@ -17,13 +17,15 @@ package kotlin.js.dom.html5 native +deprecated("Use declaration from kotlin.browser") public val localStorage: org.w3c.dom.Storage = noImpl native +deprecated("Use declaration from kotlin.browser") public val sessionStorage: org.w3c.dom.Storage = noImpl native -deprecated("Use org.w3c.dom") +deprecated("Use declarations from org.w3c.dom") public trait Storage { public val length: Int get() = noImpl diff --git a/libraries/idl/org.khronos.webgl.idl b/libraries/idl/org.khronos.webgl.idl index c153831122d..6d607e6bc4c 100644 --- a/libraries/idl/org.khronos.webgl.idl +++ b/libraries/idl/org.khronos.webgl.idl @@ -741,4 +741,291 @@ dictionary WebGLContextEventInit : EventInit { DOMString statusMessage; }; +/* + * typedarray.idl + * + * TypedArray IDL definitions scraped from the Khronos specification. + * + * Original Khronos Working Draft: + * + * https://www.khronos.org/registry/typedarray/specs/latest/ + */ + +[ Constructor(unsigned long length) ] +interface ArrayBuffer { + readonly attribute unsigned long byteLength; + ArrayBuffer slice(long begin, optional long end); + static boolean isView(any value); +}; + +ArrayBuffer implements Transferable; + +[NoInterfaceObject] +interface ArrayBufferView { + readonly attribute ArrayBuffer buffer; + readonly attribute unsigned long byteOffset; + readonly attribute unsigned long byteLength; +}; + + +// The 'byte' type does not currently exist in Web IDL. +// In this IDL, it should be a signed 8 bit type. +[ + Constructor(unsigned long length), + Constructor(Int8Array array), + Constructor(byte[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Int8Array { + const long BYTES_PER_ELEMENT = 1; + + readonly attribute unsigned long length; + + getter byte get(unsigned long index); + setter void set(unsigned long index, byte value); + void set(Int8Array array, optional unsigned long offset); + void set(byte[] array, optional unsigned long offset); + Int8Array subarray(long start, long end); +}; +Int8Array implements ArrayBufferView; + + +// The 'unsigned byte' type does not currently exist in Web IDL, though +// 'octet' is equivalent. +[ + Constructor(unsigned long length), + Constructor(Uint8Array array), + Constructor(octet[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Uint8Array { + const long BYTES_PER_ELEMENT = 1; + + readonly attribute unsigned long length; + + getter octet get(unsigned long index); + setter void set(unsigned long index, octet value); + void set(Uint8Array array, optional unsigned long offset); + void set(octet[] array, optional unsigned long offset); + Uint8Array subarray(long start, long end); +}; +Uint8Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Uint8ClampedArray array), + Constructor(octet[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Uint8ClampedArray { + const long BYTES_PER_ELEMENT = 1; + + readonly attribute unsigned long length; + + getter octet get(unsigned long index); + setter void set(unsigned long index, [Clamp] octet value); + void set(Uint8ClampedArray array, optional unsigned long offset); + void set(octet[] array, optional unsigned long offset); + Uint8ClampedArray subarray(long start, long end); +}; +Uint8ClampedArray implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Int16Array array), + Constructor(short[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Int16Array { + const long BYTES_PER_ELEMENT = 2; + + readonly attribute unsigned long length; + + getter short get(unsigned long index); + setter void set(unsigned long index, short value); + void set(Int16Array array, optional unsigned long offset); + void set(short[] array, optional unsigned long offset); + Int16Array subarray(long start, long end); +}; +Int16Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Uint16Array array), + Constructor(unsigned short[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Uint16Array { + const long BYTES_PER_ELEMENT = 2; + + readonly attribute unsigned long length; + + getter unsigned short get(unsigned long index); + setter void set(unsigned long index, unsigned short value); + void set(Uint16Array array, optional unsigned long offset); + void set(unsigned short[] array, optional unsigned long offset); + Uint16Array subarray(long start, long end); +}; +Uint16Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Int32Array array), + Constructor(long[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Int32Array { + const long BYTES_PER_ELEMENT = 4; + + readonly attribute unsigned long length; + + getter long get(unsigned long index); + setter void set(unsigned long index, long value); + void set(Int32Array array, optional unsigned long offset); + void set(long[] array, optional unsigned long offset); + Int32Array subarray(long start, long end); +}; +Int32Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Uint32Array array), + Constructor(unsigned long[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Uint32Array { + const long BYTES_PER_ELEMENT = 4; + + readonly attribute unsigned long length; + + getter unsigned long get(unsigned long index); + setter void set(unsigned long index, unsigned long value); + void set(Uint32Array array, optional unsigned long offset); + void set(unsigned long[] array, optional unsigned long offset); + Uint32Array subarray(long start, long end); +}; +Uint32Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Float32Array array), + Constructor(unrestricted float[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Float32Array { + const long BYTES_PER_ELEMENT = 4; + + readonly attribute unsigned long length; + + getter unrestricted float get(unsigned long index); + setter void set(unsigned long index, unrestricted float value); + void set(Float32Array array, optional unsigned long offset); + void set(unrestricted float[] array, optional unsigned long offset); + Float32Array subarray(long start, long end); +}; +Float32Array implements ArrayBufferView; + + +[ + Constructor(unsigned long length), + Constructor(Float64Array array), + Constructor(unrestricted double[] array), + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, optional unsigned long length) +] +interface Float64Array { + const long BYTES_PER_ELEMENT = 8; + + readonly attribute unsigned long length; + + getter unrestricted double get(unsigned long index); + setter void set(unsigned long index, unrestricted double value); + void set(Float64Array array, optional unsigned long offset); + void set(unrestricted double[] array, optional unsigned long offset); + Float64Array subarray(long start, long end); +}; +Float64Array implements ArrayBufferView; + + +[ + Constructor(ArrayBuffer buffer, + optional unsigned long byteOffset, + optional unsigned long byteLength) +] +interface DataView { + // Gets the value of the given type at the specified byte offset + // from the start of the view. There is no alignment constraint; + // multi-byte values may be fetched from any offset. + // + // For multi-byte values, the optional littleEndian argument + // indicates whether a big-endian or little-endian value should be + // read. If false or undefined, a big-endian value is read. + // + // These methods raise an INDEX_SIZE_ERR exception if they would read + // beyond the end of the view. + byte getInt8(unsigned long byteOffset); + octet getUint8(unsigned long byteOffset); + short getInt16(unsigned long byteOffset, + optional boolean littleEndian); + unsigned short getUint16(unsigned long byteOffset, + optional boolean littleEndian); + long getInt32(unsigned long byteOffset, + optional boolean littleEndian); + unsigned long getUint32(unsigned long byteOffset, + optional boolean littleEndian); + unrestricted float getFloat32(unsigned long byteOffset, + optional boolean littleEndian); + unrestricted double getFloat64(unsigned long byteOffset, + optional boolean littleEndian); + + // Stores a value of the given type at the specified byte offset + // from the start of the view. There is no alignment constraint; + // multi-byte values may be stored at any offset. + // + // For multi-byte values, the optional littleEndian argument + // indicates whether the value should be stored in big-endian or + // little-endian byte order. If false or undefined, the value is + // stored in big-endian byte order. + // + // These methods throw exceptions if they would write beyond the end + // of the view. + void setInt8(unsigned long byteOffset, + byte value); + void setUint8(unsigned long byteOffset, + octet value); + void setInt16(unsigned long byteOffset, + short value, + optional boolean littleEndian); + void setUint16(unsigned long byteOffset, + unsigned short value, + optional boolean littleEndian); + void setInt32(unsigned long byteOffset, + long value, + optional boolean littleEndian); + void setUint32(unsigned long byteOffset, + unsigned long value, + optional boolean littleEndian); + void setFloat32(unsigned long byteOffset, + unrestricted float value, + optional boolean littleEndian); + void setFloat64(unsigned long byteOffset, + unrestricted double value, + optional boolean littleEndian); +}; +DataView implements ArrayBufferView; + diff --git a/libraries/idl/org.w3c.xhr.idl b/libraries/idl/org.w3c.xhr.idl index 3cebe3f77f7..cd6af9e97e1 100644 --- a/libraries/idl/org.w3c.xhr.idl +++ b/libraries/idl/org.w3c.xhr.idl @@ -62,19 +62,17 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { readonly attribute USVString responseText; [Exposed=Window] readonly attribute Document? responseXML; }; -typedef (File or USVString) FormDataEntryValue; +typedef (Blob or USVString) FormDataEntryValue; [Constructor(optional HTMLFormElement form), Exposed=(Window,Worker)] interface FormData { - void append(USVString name, Blob value, optional USVString filename); - void append(USVString name, USVString value); + void append(USVString name, FormDataEntryValue value); void delete(USVString name); FormDataEntryValue? get(USVString name); sequence getAll(USVString name); boolean has(USVString name); - void set(USVString name, Blob value, optional USVString filename); - void set(USVString name, USVString value); + void set(USVString name, FormDataEntryValue value); iterable; }; [Constructor(DOMString type, optional ProgressEventInit eventInitDict), diff --git a/libraries/tools/idl2k/src/main/antlr4/org/antlr/webidl/WebIDL.g4 b/libraries/tools/idl2k/src/main/antlr4/org/antlr/webidl/WebIDL.g4 index 7a74259c81c..c9540d4bfc7 100644 --- a/libraries/tools/idl2k/src/main/antlr4/org/antlr/webidl/WebIDL.g4 +++ b/libraries/tools/idl2k/src/main/antlr4/org/antlr/webidl/WebIDL.g4 @@ -464,21 +464,6 @@ nonAnyType | 'Date' typeSuffix | 'RegExp' typeSuffix | 'DOMException' typeSuffix - | bufferRelatedType typeSuffix -; - -bufferRelatedType - : 'ArrayBuffer' - | 'DataView' - | 'Int8Array' - | 'Int16Array' - | 'Int32Array' - | 'Uint8Array' - | 'Uint16Array' - | 'Uint32Array' - | 'Uint8ClampedArray' - | 'Float32Array' - | 'Float64Array' ; constType diff --git a/libraries/tools/idl2k/src/main/kotlin/download.kt b/libraries/tools/idl2k/src/main/kotlin/download.kt index 48e1748b976..37e3c0a03bf 100644 --- a/libraries/tools/idl2k/src/main/kotlin/download.kt +++ b/libraries/tools/idl2k/src/main/kotlin/download.kt @@ -37,7 +37,8 @@ val urls = listOf( "https://raw.githubusercontent.com/whatwg/fetch/master/Overview.src.html" to "org.w3c.fetch", "http://www.w3.org/TR/vibration/" to "org.w3c.vibration", "http://dev.w3.org/csswg/cssom/" to "org.w3c.dom.css", - "https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl" to "org.khronos.webgl" + "https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl" to "org.khronos.webgl", + "https://www.khronos.org/registry/typedarray/specs/latest/typedarray.idl" to "org.khronos.webgl" ) fun main(args: Array) { diff --git a/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt b/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt index 5d3efa754ca..f57ae5eadd8 100644 --- a/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt +++ b/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt @@ -23,10 +23,14 @@ private val typeMapper = mapOf( "unsignedlonglong" to "Long", "longlong" to "Long", "unsignedshort" to "Short", + "unsignedbyte" to "Byte", + "octet" to "Byte", "void" to "Unit", "boolean" to "Boolean", + "byte" to "Byte", "short" to "Short", "long" to "Int", + "float" to "Float", "double" to "Double", "any" to "Any?", "DOMTimeStamp" to "Number", @@ -38,8 +42,6 @@ private val typeMapper = mapOf( "DOMString" to "String", "ByteString" to "String", "DOMError" to "dynamic", - "Uint8ClampedArray" to "dynamic", // TODO think of native arrays, - "ArrayBuffer" to "dynamic", "Elements" to "dynamic", "Date" to "Date", "" to "dynamic"