fix: incorrect declarations
This commit is contained in:
parent
2cfdd8e335
commit
567eaa8514
11
src/me/topchetoeu/jscript/js/lib.d.ts
vendored
11
src/me/topchetoeu/jscript/js/lib.d.ts
vendored
@ -489,8 +489,11 @@ interface FileStat {
|
|||||||
interface File {
|
interface File {
|
||||||
readonly pointer: Promise<number>;
|
readonly pointer: Promise<number>;
|
||||||
readonly length: Promise<number>;
|
readonly length: Promise<number>;
|
||||||
read(buff: number[], n: number): Promise<number>;
|
readonly mode: Promise<'' | 'r' | 'rw'>;
|
||||||
|
|
||||||
|
read(n: number): Promise<number[]>;
|
||||||
write(buff: number[]): Promise<void>;
|
write(buff: number[]): Promise<void>;
|
||||||
|
close(): Promise<void>;
|
||||||
setPointer(val: number): Promise<void>;
|
setPointer(val: number): Promise<void>;
|
||||||
}
|
}
|
||||||
interface Filesystem {
|
interface Filesystem {
|
||||||
@ -503,6 +506,11 @@ interface Filesystem {
|
|||||||
exists(path: string): Promise<boolean>;
|
exists(path: string): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Encoding {
|
||||||
|
encode(val: string): number[];
|
||||||
|
decode(val: number[]): string;
|
||||||
|
}
|
||||||
|
|
||||||
declare var String: StringConstructor;
|
declare var String: StringConstructor;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
declare const arguments: IArguments;
|
declare const arguments: IArguments;
|
||||||
@ -529,6 +537,7 @@ declare var Object: ObjectConstructor;
|
|||||||
declare var Symbol: SymbolConstructor;
|
declare var Symbol: SymbolConstructor;
|
||||||
declare var Promise: PromiseConstructor;
|
declare var Promise: PromiseConstructor;
|
||||||
declare var Math: MathObject;
|
declare var Math: MathObject;
|
||||||
|
declare var Encoding: Encoding;
|
||||||
declare var fs: Filesystem;
|
declare var fs: Filesystem;
|
||||||
|
|
||||||
declare var Error: ErrorConstructor;
|
declare var Error: ErrorConstructor;
|
||||||
|
@ -12,6 +12,35 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
|||||||
public class FileLib {
|
public class FileLib {
|
||||||
public final File file;
|
public final File file;
|
||||||
|
|
||||||
|
@NativeGetter public PromiseLib pointer(Context ctx) {
|
||||||
|
return PromiseLib.await(ctx, () -> {
|
||||||
|
try {
|
||||||
|
return file.getPtr();
|
||||||
|
}
|
||||||
|
catch (FilesystemException e) { throw e.toEngineException(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@NativeGetter public PromiseLib length(Context ctx) {
|
||||||
|
return PromiseLib.await(ctx, () -> {
|
||||||
|
try {
|
||||||
|
long curr = file.getPtr();
|
||||||
|
file.setPtr(0, 2);
|
||||||
|
long res = file.getPtr();
|
||||||
|
file.setPtr(curr, 0);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (FilesystemException e) { throw e.toEngineException(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@NativeGetter public PromiseLib getMode(Context ctx) {
|
||||||
|
return PromiseLib.await(ctx, () -> {
|
||||||
|
try {
|
||||||
|
return file.mode().name;
|
||||||
|
}
|
||||||
|
catch (FilesystemException e) { throw e.toEngineException(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Native public PromiseLib read(Context ctx, int n) {
|
@Native public PromiseLib read(Context ctx, int n) {
|
||||||
return PromiseLib.await(ctx, () -> {
|
return PromiseLib.await(ctx, () -> {
|
||||||
try {
|
try {
|
||||||
@ -44,14 +73,6 @@ public class FileLib {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@NativeGetter public PromiseLib pointer(Context ctx) {
|
|
||||||
return PromiseLib.await(ctx, () -> {
|
|
||||||
try {
|
|
||||||
return file.getPtr();
|
|
||||||
}
|
|
||||||
catch (FilesystemException e) { throw e.toEngineException(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@Native public PromiseLib setPointer(Context ctx, long ptr) {
|
@Native public PromiseLib setPointer(Context ctx, long ptr) {
|
||||||
return PromiseLib.await(ctx, () -> {
|
return PromiseLib.await(ctx, () -> {
|
||||||
try {
|
try {
|
||||||
@ -61,26 +82,6 @@ public class FileLib {
|
|||||||
catch (FilesystemException e) { throw e.toEngineException(); }
|
catch (FilesystemException e) { throw e.toEngineException(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@NativeGetter("length") public PromiseLib getLength(Context ctx) {
|
|
||||||
return PromiseLib.await(ctx, () -> {
|
|
||||||
try {
|
|
||||||
long curr = file.getPtr();
|
|
||||||
file.setPtr(0, 2);
|
|
||||||
long res = file.getPtr();
|
|
||||||
file.setPtr(curr, 0);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
catch (FilesystemException e) { throw e.toEngineException(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@NativeGetter("mode") public PromiseLib getMode(Context ctx) {
|
|
||||||
return PromiseLib.await(ctx, () -> {
|
|
||||||
try {
|
|
||||||
return file.mode().name;
|
|
||||||
}
|
|
||||||
catch (FilesystemException e) { throw e.toEngineException(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileLib(File file) {
|
public FileLib(File file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
@ -289,7 +289,7 @@ import me.topchetoeu.jscript.interop.Native;
|
|||||||
|
|
||||||
ctx.engine.pushMsg(true, ctx, new NativeFunction((_ctx, _thisArg, _args) -> {
|
ctx.engine.pushMsg(true, ctx, new NativeFunction((_ctx, _thisArg, _args) -> {
|
||||||
for (var handle : handles) handle.rejected.call(handle.ctx, null, val);
|
for (var handle : handles) handle.rejected.call(handle.ctx, null, val);
|
||||||
if (handles.size() == 0) {
|
if (!handled) {
|
||||||
Values.printError(new EngineException(val).setCtx(ctx.environment(), ctx.engine), "(in promise)");
|
Values.printError(new EngineException(val).setCtx(ctx.environment(), ctx.engine), "(in promise)");
|
||||||
}
|
}
|
||||||
handles = null;
|
handles = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user