mirror of
https://github.com/denoland/deno.git
synced 2024-10-31 09:14:20 -04:00
31 lines
980 B
TypeScript
31 lines
980 B
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import * as msg from "gen/cli/msg_generated";
|
|
import * as flatbuffers from "./flatbuffers";
|
|
import { assert } from "./util";
|
|
import * as dispatch from "./dispatch";
|
|
|
|
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 = 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 = {};
|
|
|
|
for (let i = 0; i < res.resourcesLength(); i++) {
|
|
const item = res.resources(i)!;
|
|
resources[item.rid()!] = item.repr()!;
|
|
}
|
|
|
|
return resources;
|
|
}
|