Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
45dafe15
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45dafe15
编写于
8月 30, 2018
作者:
R
Ryan Dahl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor libdeno.send() code to reduce boilerplate.
Also removes assignCmdId as it's currently unused.
上级
cce3bd47
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
137 deletion
+66
-137
js/fbs_util.ts
js/fbs_util.ts
+26
-0
js/fetch.ts
js/fetch.ts
+3
-9
js/main.ts
js/main.ts
+10
-24
js/os.ts
js/os.ts
+22
-82
js/timers.ts
js/timers.ts
+5
-14
js/util.ts
js/util.ts
+0
-8
未找到文件。
js/fbs_util.ts
0 → 100644
浏览文件 @
45dafe15
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import
{
libdeno
}
from
"
./libdeno
"
;
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
{
maybeThrowError
}
from
"
./errors
"
;
import
{
deno
as
fbs
}
from
"
gen/msg_generated
"
;
export
function
send
(
builder
:
flatbuffers
.
Builder
,
msgType
:
fbs
.
Any
,
msg
:
flatbuffers
.
Offset
):
null
|
fbs
.
Base
{
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
msgType
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
if
(
resBuf
==
null
)
{
return
null
;
}
else
{
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
return
baseRes
;
}
}
js/fetch.ts
浏览文件 @
45dafe15
...
...
@@ -8,7 +8,7 @@ import {
notImplemented
}
from
"
./util
"
;
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
{
libdeno
}
from
"
./libdeno
"
;
import
{
send
}
from
"
./fbs_util
"
;
import
{
deno
as
fbs
}
from
"
gen/msg_generated
"
;
import
{
Headers
,
...
...
@@ -166,14 +166,8 @@ class FetchRequest {
fbs
.
FetchReq
.
addId
(
builder
,
this
.
id
);
fbs
.
FetchReq
.
addUrl
(
builder
,
url
);
const
msg
=
fbs
.
FetchReq
.
endFetchReq
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
FetchReq
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
==
null
);
//console.log("FetchReq sent", builder);
const
res
=
send
(
builder
,
fbs
.
Any
.
FetchReq
,
msg
);
assert
(
res
==
null
);
}
}
...
...
js/main.ts
浏览文件 @
45dafe15
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
{
deno
as
fbs
}
from
"
gen/msg_generated
"
;
import
{
assert
,
assignCmdId
,
log
,
setLogDebug
}
from
"
./util
"
;
import
{
assert
,
log
,
setLogDebug
}
from
"
./util
"
;
import
*
as
os
from
"
./os
"
;
import
{
DenoCompiler
}
from
"
./compiler
"
;
import
{
libdeno
}
from
"
./libdeno
"
;
import
*
as
timers
from
"
./timers
"
;
import
{
onFetchRes
}
from
"
./fetch
"
;
import
{
argv
}
from
"
./deno
"
;
import
{
send
}
from
"
./fbs_util
"
;
function
s
tartMsg
(
cmdId
:
number
):
Uint8Array
{
function
s
endStart
():
fbs
.
StartRes
{
const
builder
=
new
flatbuffers
.
Builder
();
fbs
.
Start
.
startStart
(
builder
);
const
startOffset
=
fbs
.
Start
.
endStart
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addCmdId
(
builder
,
cmdId
);
fbs
.
Base
.
addMsg
(
builder
,
startOffset
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
Start
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
)
);
return
builder
.
asUint8Array
()
;
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
Start
,
startOffset
);
assert
(
baseRes
!=
null
);
assert
(
fbs
.
Any
.
StartRes
===
baseRes
!
.
msgType
()
);
const
startRes
=
new
fbs
.
StartRes
(
);
assert
(
baseRes
!
.
msg
(
startRes
)
!=
null
);
return
startRes
;
}
function
onMessage
(
ui8
:
Uint8Array
)
{
...
...
@@ -64,22 +65,7 @@ export default function denoMain() {
// First we send an empty "Start" message to let the privlaged side know we
// are ready. The response should be a "StartRes" message containing the CLI
// argv and other info.
const
cmdId
=
assignCmdId
();
const
res
=
libdeno
.
send
(
startMsg
(
cmdId
));
// TODO(ry) Remove this conditional once main.rs gets up to speed.
if
(
res
==
null
)
{
console
.
log
(
`The 'Start' message got a null response. Normally this would
be an error but main.rs currently does this."); Exiting without error.`
);
return
;
}
// Deserialize res into startResMsg.
const
bb
=
new
flatbuffers
.
ByteBuffer
(
res
);
const
base
=
fbs
.
Base
.
getRootAsBase
(
bb
);
assert
(
fbs
.
Any
.
StartRes
===
base
.
msgType
());
const
startResMsg
=
new
fbs
.
StartRes
();
assert
(
base
.
msg
(
startResMsg
)
!=
null
);
const
startResMsg
=
sendStart
();
setLogDebug
(
startResMsg
.
debugFlag
());
...
...
js/os.ts
浏览文件 @
45dafe15
...
...
@@ -3,20 +3,15 @@ import { ModuleInfo } from "./types";
import
{
deno
as
fbs
}
from
"
gen/msg_generated
"
;
import
{
assert
}
from
"
./util
"
;
import
*
as
util
from
"
./util
"
;
import
{
maybeThrowError
}
from
"
./errors
"
;
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
{
libdeno
}
from
"
./libdeno
"
;
import
{
send
}
from
"
./fbs_util
"
;
export
function
exit
(
exitCode
=
0
):
never
{
const
builder
=
new
flatbuffers
.
Builder
();
fbs
.
Exit
.
startExit
(
builder
);
fbs
.
Exit
.
addCode
(
builder
,
exitCode
);
const
msg
=
fbs
.
Exit
.
endExit
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
Exit
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
libdeno
.
send
(
builder
.
asUint8Array
());
send
(
builder
,
fbs
.
Any
.
Exit
,
msg
);
return
util
.
unreachable
();
}
...
...
@@ -33,21 +28,11 @@ export function codeFetch(
fbs
.
CodeFetch
.
addModuleSpecifier
(
builder
,
moduleSpecifier_
);
fbs
.
CodeFetch
.
addContainingFile
(
builder
,
containingFile_
);
const
msg
=
fbs
.
CodeFetch
.
endCodeFetch
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
CodeFetch
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
!=
null
);
// Process CodeFetchRes
// TypeScript does not track `assert` from a CFA perspective, therefore not
// null assertion `!`
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
assert
(
fbs
.
Any
.
CodeFetchRes
===
baseRes
.
msgType
());
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
CodeFetch
,
msg
);
assert
(
baseRes
!=
null
);
assert
(
fbs
.
Any
.
CodeFetchRes
===
baseRes
!
.
msgType
());
const
codeFetchRes
=
new
fbs
.
CodeFetchRes
();
assert
(
baseRes
.
msg
(
codeFetchRes
)
!=
null
);
assert
(
baseRes
!
.
msg
(
codeFetchRes
)
!=
null
);
const
r
=
{
moduleName
:
codeFetchRes
.
moduleName
(),
filename
:
codeFetchRes
.
filename
(),
...
...
@@ -72,17 +57,8 @@ export function codeCache(
fbs
.
CodeCache
.
addSourceCode
(
builder
,
sourceCode_
);
fbs
.
CodeCache
.
addOutputCode
(
builder
,
outputCode_
);
const
msg
=
fbs
.
CodeCache
.
endCodeCache
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
CodeCache
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
// Expect null or error.
if
(
resBuf
!=
null
)
{
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
}
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
CodeCache
,
msg
);
assert
(
baseRes
==
null
);
// Expect null or error.
}
/**
...
...
@@ -119,18 +95,11 @@ export function makeTempDirSync({
fbs
.
MakeTempDir
.
addSuffix
(
builder
,
fbSuffix
);
}
const
msg
=
fbs
.
MakeTempDir
.
endMakeTempDir
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
MakeTempDir
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
!=
null
);
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
assert
(
fbs
.
Any
.
MakeTempDirRes
===
baseRes
.
msgType
());
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
MakeTempDir
,
msg
);
assert
(
baseRes
!=
null
);
assert
(
fbs
.
Any
.
MakeTempDirRes
===
baseRes
!
.
msgType
());
const
res
=
new
fbs
.
MakeTempDirRes
();
assert
(
baseRes
.
msg
(
res
)
!=
null
);
assert
(
baseRes
!
.
msg
(
res
)
!=
null
);
const
path
=
res
.
path
();
assert
(
path
!=
null
);
return
path
!
;
...
...
@@ -149,23 +118,13 @@ export function readFileSync(filename: string): Uint8Array {
fbs
.
ReadFileSync
.
startReadFileSync
(
builder
);
fbs
.
ReadFileSync
.
addFilename
(
builder
,
filename_
);
const
msg
=
fbs
.
ReadFileSync
.
endReadFileSync
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
ReadFileSync
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
!=
null
);
// TypeScript does not track `assert` from a CFA perspective, therefore not
// null assertion `!`
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
assert
(
fbs
.
Any
.
ReadFileSyncRes
===
baseRes
.
msgType
());
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
ReadFileSync
,
msg
);
assert
(
baseRes
!=
null
);
assert
(
fbs
.
Any
.
ReadFileSyncRes
===
baseRes
!
.
msgType
());
const
res
=
new
fbs
.
ReadFileSyncRes
();
assert
(
baseRes
.
msg
(
res
)
!=
null
);
assert
(
baseRes
!
.
msg
(
res
)
!=
null
);
const
dataArray
=
res
.
dataArray
();
assert
(
dataArray
!=
null
);
// TypeScript cannot track assertion above, therefore not null assertion
return
new
Uint8Array
(
dataArray
!
);
}
...
...
@@ -226,22 +185,12 @@ function statSyncInner(filename: string, lstat: boolean): FileInfo {
fbs
.
StatSync
.
addFilename
(
builder
,
filename_
);
fbs
.
StatSync
.
addLstat
(
builder
,
lstat
);
const
msg
=
fbs
.
StatSync
.
endStatSync
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
StatSync
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
!=
null
);
// TypeScript does not track `assert` from a CFA perspective, therefore not
// null assertion `!`
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
assert
(
fbs
.
Any
.
StatSyncRes
===
baseRes
.
msgType
());
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
StatSync
,
msg
);
assert
(
baseRes
!=
null
);
assert
(
fbs
.
Any
.
StatSyncRes
===
baseRes
!
.
msgType
());
const
res
=
new
fbs
.
StatSyncRes
();
assert
(
baseRes
.
msg
(
res
)
!=
null
);
// TypeScript cannot track assertion above, therefore not null assertion
return
new
FileInfo
(
baseRes
.
msg
(
res
)
!
);
assert
(
baseRes
!
.
msg
(
res
)
!=
null
);
return
new
FileInfo
(
res
);
}
export
function
writeFileSync
(
...
...
@@ -265,14 +214,5 @@ export function writeFileSync(
fbs
.
WriteFileSync
.
addData
(
builder
,
dataOffset
);
fbs
.
WriteFileSync
.
addPerm
(
builder
,
perm
);
const
msg
=
fbs
.
WriteFileSync
.
endWriteFileSync
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
WriteFileSync
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
if
(
resBuf
!=
null
)
{
const
bb
=
new
flatbuffers
.
ByteBuffer
(
new
Uint8Array
(
resBuf
!
));
const
baseRes
=
fbs
.
Base
.
getRootAsBase
(
bb
);
maybeThrowError
(
baseRes
);
}
send
(
builder
,
fbs
.
Any
.
WriteFileSync
,
msg
);
}
js/timers.ts
浏览文件 @
45dafe15
...
...
@@ -3,7 +3,7 @@ import { assert } from "./util";
import
*
as
util
from
"
./util
"
;
import
{
deno
as
fbs
}
from
"
gen/msg_generated
"
;
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
{
libdeno
}
from
"
./libdeno
"
;
import
{
send
}
from
"
./fbs_util
"
;
let
nextTimerId
=
1
;
...
...
@@ -60,13 +60,8 @@ function startTimer(
fbs
.
TimerStart
.
addInterval
(
builder
,
timer
.
interval
);
fbs
.
TimerStart
.
addDelay
(
builder
,
timer
.
delay
);
const
msg
=
fbs
.
TimerStart
.
endTimerStart
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
TimerStart
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
==
null
);
const
baseRes
=
send
(
builder
,
fbs
.
Any
.
TimerStart
,
msg
);
assert
(
baseRes
==
null
);
return
timer
.
id
;
}
...
...
@@ -95,10 +90,6 @@ export function clearTimer(id: number) {
fbs
.
TimerClear
.
startTimerClear
(
builder
);
fbs
.
TimerClear
.
addId
(
builder
,
id
);
const
msg
=
fbs
.
TimerClear
.
endTimerClear
(
builder
);
fbs
.
Base
.
startBase
(
builder
);
fbs
.
Base
.
addMsg
(
builder
,
msg
);
fbs
.
Base
.
addMsgType
(
builder
,
fbs
.
Any
.
TimerClear
);
builder
.
finish
(
fbs
.
Base
.
endBase
(
builder
));
const
resBuf
=
libdeno
.
send
(
builder
.
asUint8Array
());
assert
(
resBuf
==
null
);
const
res
=
send
(
builder
,
fbs
.
Any
.
TimerClear
,
msg
);
assert
(
res
==
null
);
}
js/util.ts
浏览文件 @
45dafe15
...
...
@@ -21,14 +21,6 @@ export function assert(cond: boolean, msg = "assert") {
}
}
let
cmdIdCounter
=
0
;
export
function
assignCmdId
():
number
{
// TODO(piscisaureus) Safely re-use so they don't overflow.
const
cmdId
=
++
cmdIdCounter
;
assert
(
cmdId
<
2
**
32
,
"
cmdId overflow
"
);
return
cmdId
;
}
export
function
typedArrayToArrayBuffer
(
ta
:
TypedArray
):
ArrayBuffer
{
const
ab
=
ta
.
buffer
.
slice
(
ta
.
byteOffset
,
ta
.
byteOffset
+
ta
.
byteLength
);
return
ab
as
ArrayBuffer
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录