1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

Rename EnvPair to KeyValue.

This commit is contained in:
Ryan Dahl 2018-11-02 20:09:10 -04:00
parent edd12b90a8
commit ee24254bad
5 changed files with 30 additions and 19 deletions

View file

@ -81,12 +81,11 @@ export function codeCache(
assert(baseRes == null); // Expect null or error.
}
function createEnv(_inner: msg.EnvironRes): { [index: string]: string } {
function createEnv(inner: msg.EnvironRes): { [index: string]: string } {
const env: { [index: string]: string } = {};
for (let i = 0; i < _inner.mapLength(); i++) {
const item = _inner.map(i)!;
for (let i = 0; i < inner.mapLength(); i++) {
const item = inner.map(i)!;
env[item.key()!] = item.value()!;
}

View file

@ -31,6 +31,7 @@ mod http_util;
pub mod isolate;
pub mod libdeno;
pub mod msg;
pub mod msg_util;
pub mod ops;
pub mod permissions;
pub mod resources;

View file

@ -182,10 +182,10 @@ table SetEnv {
}
table EnvironRes {
map: [EnvPair];
map: [KeyValue];
}
table EnvPair {
table KeyValue {
key: string;
value: string;
}

21
src/msg_util.rs Normal file
View file

@ -0,0 +1,21 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Helpers for serialization.
use flatbuffers;
use msg;
pub fn serialize_key_value<'bldr>(
builder: &mut flatbuffers::FlatBufferBuilder<'bldr>,
key: &str,
value: &str,
) -> flatbuffers::WIPOffset<msg::KeyValue<'bldr>> {
let key = builder.create_string(&key);
let value = builder.create_string(&value);
msg::KeyValue::create(
builder,
&msg::KeyValueArgs {
key: Some(key),
value: Some(value),
..Default::default()
},
)
}

View file

@ -8,6 +8,7 @@ use isolate::Isolate;
use isolate::IsolateState;
use isolate::Op;
use msg;
use msg_util;
use resources;
use resources::Resource;
use version;
@ -358,19 +359,8 @@ fn op_env(
let builder = &mut FlatBufferBuilder::new();
let vars: Vec<_> = std::env::vars()
.map(|(key, value)| {
let key = builder.create_string(&key);
let value = builder.create_string(&value);
msg::EnvPair::create(
builder,
&msg::EnvPairArgs {
key: Some(key),
value: Some(value),
..Default::default()
},
)
}).collect();
.map(|(key, value)| msg_util::serialize_key_value(builder, &key, &value))
.collect();
let tables = builder.create_vector(&vars);
let inner = msg::EnvironRes::create(
builder,