mirror of
https://github.com/denoland/deno.git
synced 2025-01-16 02:48:52 -05:00
2235dd795d
* Revert "port more ops to JSON (#2809)" This reverts commit137f33733d
. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit79f82cf10e
. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit5b2baa5c99
.
29 lines
908 B
TypeScript
29 lines
908 B
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import { assert } from "./util";
|
|
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
|
|
|
export interface ResourceMap {
|
|
[rid: number]: string;
|
|
}
|
|
|
|
/** Returns a map of open _file like_ resource ids along with their string
|
|
* representation.
|
|
*/
|
|
export function resources(): ResourceMap {
|
|
const builder = flatbuffers.createBuilder();
|
|
const inner = msg.Resource.createResource(builder, 0, 0);
|
|
const baseRes = sendSync(builder, msg.Any.Resources, inner);
|
|
assert(baseRes !== null);
|
|
assert(msg.Any.ResourcesRes === baseRes!.innerType());
|
|
const res = new msg.ResourcesRes();
|
|
assert(baseRes!.inner(res) !== null);
|
|
|
|
const resources: ResourceMap = {};
|
|
|
|
for (let i = 0; i < res.resourcesLength(); i++) {
|
|
const item = res.resources(i)!;
|
|
resources[item.rid()!] = item.repr()!;
|
|
}
|
|
|
|
return resources;
|
|
}
|