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 {
|
||||
readonly pointer: 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>;
|
||||
close(): Promise<void>;
|
||||
setPointer(val: number): Promise<void>;
|
||||
}
|
||||
interface Filesystem {
|
||||
@ -503,6 +506,11 @@ interface Filesystem {
|
||||
exists(path: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
interface Encoding {
|
||||
encode(val: string): number[];
|
||||
decode(val: number[]): string;
|
||||
}
|
||||
|
||||
declare var String: StringConstructor;
|
||||
//@ts-ignore
|
||||
declare const arguments: IArguments;
|
||||
@ -529,6 +537,7 @@ declare var Object: ObjectConstructor;
|
||||
declare var Symbol: SymbolConstructor;
|
||||
declare var Promise: PromiseConstructor;
|
||||
declare var Math: MathObject;
|
||||
declare var Encoding: Encoding;
|
||||
declare var fs: Filesystem;
|
||||
|
||||
declare var Error: ErrorConstructor;
|
||||
|
@ -12,6 +12,35 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
||||
public class FileLib {
|
||||
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) {
|
||||
return PromiseLib.await(ctx, () -> {
|
||||
try {
|
||||
@ -44,14 +73,6 @@ public class FileLib {
|
||||
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) {
|
||||
return PromiseLib.await(ctx, () -> {
|
||||
try {
|
||||
@ -61,26 +82,6 @@ public class FileLib {
|
||||
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) {
|
||||
this.file = file;
|
||||
|
@ -289,7 +289,7 @@ import me.topchetoeu.jscript.interop.Native;
|
||||
|
||||
ctx.engine.pushMsg(true, ctx, new NativeFunction((_ctx, _thisArg, _args) -> {
|
||||
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)");
|
||||
}
|
||||
handles = null;
|
||||
|
Loading…
Reference in New Issue
Block a user