1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00
denoland-deno/js/resources.ts

32 lines
980 B
TypeScript
Raw Normal View History

2019-01-21 14:03:30 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as msg from "gen/cli/msg_generated";
2018-10-30 15:58:55 -04:00
import * as flatbuffers from "./flatbuffers";
import { assert } from "./util";
import * as dispatch from "./dispatch";
export interface ResourceMap {
[rid: number]: string;
}
2018-11-08 23:07:48 -05:00
/** Returns a map of open _file like_ resource ids along with their string
* representation.
*/
export function resources(): ResourceMap {
2018-10-30 15:58:55 -04:00
const builder = flatbuffers.createBuilder();
const inner = msg.Resource.createResource(builder, 0, 0);
2018-10-30 15:58:55 -04:00
const baseRes = dispatch.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 = {};
2018-10-30 15:58:55 -04:00
for (let i = 0; i < res.resourcesLength(); i++) {
const item = res.resources(i)!;
resources[item.rid()!] = item.repr()!;
}
return resources;
}