Rusty_v8
Posted 跨链技术践行者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rusty_v8相关的知识,希望对你有一定的参考价值。
Overview
Rusty_v8 is a part of the Deno project but it's not located inside the main Deno repository. Therefore we treat it as a third-party component.
V8 is written in C++, while Deno is written in Rust. To have them interwork, rusty_v8 was conceived. The purpose of rusty_v8 library is to provide high-quality rust bindings to v8's C++ APIs. Rusty_v8 is very efficient. There is no additional call overhead.
In terms of the API, Rusty_v8 tries it's best to match the V8 APIs as much as possible. In most cases, it'd be a simple mapping.
Rusty_v8 is efficient and doesn't introduce additional call overhead.
Example
Some code examples will help to understand rusty_v8 better.
Consider one of the functions in rusty_v8's String implementation:
pub fn length(&self) -> usize {
unsafe { v8__String__Length(self) as usize }
}
This function is part of the implementation of the String class in rust. When the length is called, it'll call v8__String__Length which is a C++ code that returns the length of v8's string data type. Very simple 1:1 mapping.
int v8__String__Length(const v8::String& self) {
return self.Length();
}
Consider one more example in rusty_v8, parse:
pub fn parse<'s>(
scope: &mut HandleScope<'s>,
json_string: Local<'_, String>,
) -> Option<Local<'s, Value>> {
unsafe {
scope
.cast_local(|sd| v8__JSON__Parse(sd.get_current_context(), &*json_string))
}
}
Rusty_v8 provides a parse function that maps to v8__JSON__Parse which is a C++ function that calls the corresponding function of v8:
const v8::Value* v8__JSON__Parse(const v8::Context& context,
const v8::String& json_string) {
return maybe_local_to_ptr(
v8::JSON::Parse(ptr_to_local(&context), ptr_to_local(&json_string)));
}
In most of the cases, rusty_v8 simply matches the v8 API.
For more information on rusty_v8 visit https://github.com/denoland/rusty_v8.
Let's move on to tokio, which makes Deno fully async.
以上是关于Rusty_v8的主要内容,如果未能解决你的问题,请参考以下文章
Xcode 8 Autocomplete Broken - 仅显示有限的用户代码片段 - 知道为啥吗?
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段