Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
c427c2df
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,发现更多精彩内容 >>
提交
c427c2df
编写于
12月 10, 2018
作者:
B
binaryta
提交者:
Ryan Dahl
12月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add TooLarge error code for buffers (#1298)
In collaboration with @yushimatenjin
上级
f2447f6a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
2 deletion
+26
-2
js/buffer.ts
js/buffer.ts
+5
-1
js/buffer_test.ts
js/buffer_test.ts
+20
-1
src/msg.fbs
src/msg.fbs
+1
-0
未找到文件。
js/buffer.ts
浏览文件 @
c427c2df
...
...
@@ -6,6 +6,7 @@
import
{
Reader
,
Writer
,
ReadResult
}
from
"
./io
"
;
import
{
assert
}
from
"
./util
"
;
import
{
TextDecoder
}
from
"
./text_encoding
"
;
import
{
DenoError
,
ErrorKind
}
from
"
./errors
"
;
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
...
...
@@ -170,7 +171,10 @@ export class Buffer implements Reader, Writer {
// don't spend all our time copying.
copyBytes
(
this
.
buf
,
this
.
buf
.
subarray
(
this
.
off
));
}
else
if
(
c
>
MAX_SIZE
-
c
-
n
)
{
throw
Error
(
"
ErrTooLarge
"
);
// TODO DenoError(TooLarge)
throw
new
DenoError
(
ErrorKind
.
TooLarge
,
"
The buffer cannot be grown beyond the maximum size.
"
);
}
else
{
// Not enough space anywhere, we need to allocate.
const
buf
=
new
Uint8Array
(
2
*
c
+
n
);
...
...
js/buffer_test.ts
浏览文件 @
c427c2df
import
{
Buffer
,
readAll
}
from
"
deno
"
;
import
*
as
deno
from
"
deno
"
;
// This code has been ported almost directly from Go's src/bytes/buffer_test.go
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE
import
{
assert
,
assertEqual
,
test
}
from
"
./test_util.ts
"
;
// N controls how many iterations of certain checks are performed.
const
N
=
100
;
let
testBytes
:
Uint8Array
|
null
;
...
...
@@ -130,6 +130,25 @@ test(async function bufferLargeByteWrites() {
check
(
buf
,
""
);
});
test
(
async
function
bufferTooLargeByteWrites
()
{
init
();
const
tmp
=
new
Uint8Array
(
72
);
const
growLen
=
Number
.
MAX_VALUE
;
const
xBytes
=
repeat
(
"
x
"
,
0
);
const
buf
=
new
Buffer
(
xBytes
.
buffer
as
ArrayBuffer
);
const
{
nread
,
eof
}
=
await
buf
.
read
(
tmp
);
let
err
;
try
{
buf
.
grow
(
growLen
);
}
catch
(
e
)
{
err
=
e
;
}
assertEqual
(
err
.
kind
,
deno
.
ErrorKind
.
TooLarge
);
assertEqual
(
err
.
name
,
"
TooLarge
"
);
});
test
(
async
function
bufferLargeByteReads
()
{
init
();
const
buf
=
new
Buffer
();
...
...
src/msg.fbs
浏览文件 @
c427c2df
...
...
@@ -105,6 +105,7 @@ enum ErrorKind: byte {
HttpCanceled,
HttpParse,
HttpOther,
TooLarge,
}
table Cwd {}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录