summaryrefslogtreecommitdiff
path: root/js/get_random_values.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-08-24 17:31:14 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-08-24 08:31:14 -0700
commit137f33733d365026903d40e7cde6e34ac6c36dcf (patch)
treee8096e119c374b199cd498ccfa1ee0ef4e6ba950 /js/get_random_values.ts
parent79f82cf10ed1dbf91346994250d7311a4d74377a (diff)
port more ops to JSON (#2809)
Diffstat (limited to 'js/get_random_values.ts')
-rw-r--r--js/get_random_values.ts18
1 files changed, 8 insertions, 10 deletions
diff --git a/js/get_random_values.ts b/js/get_random_values.ts
index d5c0828c5..154e77f75 100644
--- a/js/get_random_values.ts
+++ b/js/get_random_values.ts
@@ -1,15 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import * as dispatch from "./dispatch";
+import { sendSync } from "./dispatch_json";
import { assert } from "./util";
-function req(
- typedArray: ArrayBufferView
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset, ArrayBufferView] {
- const builder = flatbuffers.createBuilder();
- const inner = msg.GetRandomValues.createGetRandomValues(builder);
- return [builder, msg.Any.GetRandomValues, inner, typedArray];
-}
-
/** Synchronously collects cryptographically secure random values. The
* underlying CSPRNG in use is Rust's `rand::rngs::ThreadRng`.
*
@@ -28,6 +21,11 @@ export function getRandomValues<
>(typedArray: T): T {
assert(typedArray !== null, "Input must not be null");
assert(typedArray.length <= 65536, "Input must not be longer than 65536");
- sendSync(...req(typedArray as ArrayBufferView));
+ const ui8 = new Uint8Array(
+ typedArray.buffer,
+ typedArray.byteOffset,
+ typedArray.byteLength
+ );
+ sendSync(dispatch.OP_GET_RANDOM_VALUES, {}, ui8);
return typedArray;
}