Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
2558d6e1
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,发现更多精彩内容 >>
提交
2558d6e1
编写于
1月 07, 2019
作者:
K
Kevin (Kun) "Kassimo" Qian
提交者:
Ryan Dahl
1月 07, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use multimap with Persistent module handle to avoid IdentityHash collision (#1466)
上级
404e6f86
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
10 deletion
+28
-10
libdeno/binding.cc
libdeno/binding.cc
+25
-8
libdeno/internal.h
libdeno/internal.h
+3
-2
未找到文件。
libdeno/binding.cc
浏览文件 @
2558d6e1
...
...
@@ -378,21 +378,26 @@ void DenoIsolate::ClearModules() {
it
->
second
.
Reset
();
}
module_map_
.
clear
();
module_filename_map_
.
clear
();
for
(
auto
it
=
module_info_map_
.
begin
();
it
!=
module_info_map_
.
end
();
it
++
)
{
it
->
second
.
second
.
Reset
();
}
module_info_map_
.
clear
();
}
void
DenoIsolate
::
RegisterModule
(
const
char
*
filename
,
v8
::
Local
<
v8
::
Module
>
module
)
{
int
id
=
module
->
GetIdentityHash
();
// v8.h says that identity hash is not necessarily unique. It seems it's quite
// unique enough for the purposes of O(1000) modules, so we use it as a
// hashmap key here. The following check is to detect collisions.
CHECK_EQ
(
0
,
module_filename_map_
.
count
(
id
));
module_filename_map_
[
id
]
=
filename
;
module_map_
.
emplace
(
std
::
piecewise_construct
,
std
::
make_tuple
(
filename
),
std
::
make_tuple
(
isolate_
,
module
));
// Identity hash is not necessarily unique
// Therefore, we store a persistent handle along with filenames
// such that we can compare the identites and select the correct module
module_info_map_
.
emplace
(
std
::
piecewise_construct
,
std
::
make_tuple
(
id
),
std
::
make_tuple
(
std
::
piecewise_construct
,
std
::
make_tuple
(
filename
),
std
::
make_tuple
(
isolate_
,
module
)));
}
v8
::
MaybeLocal
<
v8
::
Module
>
CompileModule
(
v8
::
Local
<
v8
::
Context
>
context
,
...
...
@@ -468,7 +473,19 @@ v8::MaybeLocal<v8::Module> ResolveCallback(v8::Local<v8::Context> context,
}
int
ref_id
=
referrer
->
GetIdentityHash
();
std
::
string
referrer_filename
=
d
->
module_filename_map_
[
ref_id
];
auto
range
=
d
->
module_info_map_
.
equal_range
(
ref_id
);
std
::
string
referrer_filename
;
for
(
auto
it
=
range
.
first
;
it
!=
range
.
second
;
++
it
)
{
// it->second: <string, v8::Persistent<v8::Module>>
// operator== compares value identities stored in the handles
// https://denolib.github.io/v8-docs/include_2v8_8h_source.html#l00487
// Due to possibilities of identity hash collision, this is necessary
if
(
it
->
second
.
second
==
referrer
)
{
referrer_filename
=
it
->
second
.
first
;
break
;
}
}
CHECK
(
referrer_filename
.
size
()
!=
0
);
v8
::
String
::
Utf8Value
specifier_
(
isolate
,
specifier
);
const
char
*
specifier_c
=
ToCString
(
specifier_
);
...
...
libdeno/internal.h
浏览文件 @
2558d6e1
...
...
@@ -58,8 +58,9 @@ class DenoIsolate {
int32_t
next_req_id_
;
void
*
user_data_
;
// identity hash -> filename
std
::
map
<
int
,
std
::
string
>
module_filename_map_
;
// identity hash -> filename, module (avoid hash collision)
std
::
multimap
<
int
,
std
::
pair
<
std
::
string
,
v8
::
Persistent
<
v8
::
Module
>>>
module_info_map_
;
// filename -> Module
std
::
map
<
std
::
string
,
v8
::
Persistent
<
v8
::
Module
>>
module_map_
;
// Set by deno_resolve_ok
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录