mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 08:34:01 -05:00
feat: add ObjectTemplate::set_immutable_proto() (#977)
This commit exposes SetImmutableProto().
This commit is contained in:
parent
15ac9f4533
commit
0605e9bc34
3 changed files with 41 additions and 0 deletions
|
@ -1122,6 +1122,10 @@ void v8__ObjectTemplate__SetAccessorProperty(const v8::ObjectTemplate& self,
|
|||
ptr_to_local(&key), ptr_to_local(&getter), ptr_to_local(&setter), attr);
|
||||
}
|
||||
|
||||
void v8__ObjectTemplate__SetImmutableProto(const v8::ObjectTemplate& self) {
|
||||
return ptr_to_local(&self)->SetImmutableProto();
|
||||
}
|
||||
|
||||
const v8::Object* v8__Object__New(v8::Isolate* isolate) {
|
||||
return local_to_ptr(v8::Object::New(isolate));
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ extern "C" {
|
|||
setter: *const FunctionTemplate,
|
||||
attr: PropertyAttribute,
|
||||
);
|
||||
fn v8__ObjectTemplate__SetImmutableProto(this: *const ObjectTemplate);
|
||||
}
|
||||
|
||||
impl Template {
|
||||
|
@ -362,4 +363,10 @@ impl ObjectTemplate {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Makes the ObjectTemplate for an immutable prototype exotic object,
|
||||
/// with an immutable proto.
|
||||
pub fn set_immutable_proto(&self) {
|
||||
unsafe { v8__ObjectTemplate__SetImmutableProto(self) };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1456,6 +1456,36 @@ fn object_template_from_function_template() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_template_immutable_proto() {
|
||||
let _setup_guard = setup();
|
||||
let isolate = &mut v8::Isolate::new(Default::default());
|
||||
{
|
||||
let scope = &mut v8::HandleScope::new(isolate);
|
||||
let object_templ = v8::ObjectTemplate::new(scope);
|
||||
object_templ.set_immutable_proto();
|
||||
let context = v8::Context::new_from_template(scope, object_templ);
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let source = r#"
|
||||
{
|
||||
let r = 0;
|
||||
|
||||
try {
|
||||
Object.setPrototypeOf(globalThis, {});
|
||||
} catch {
|
||||
r = 42;
|
||||
}
|
||||
|
||||
String(r);
|
||||
}
|
||||
"#;
|
||||
let actual = eval(scope, source).unwrap();
|
||||
let expected = v8::String::new(scope, "42").unwrap();
|
||||
|
||||
assert!(actual == expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn function_template_signature() {
|
||||
let _setup_guard = setup();
|
||||
|
|
Loading…
Reference in a new issue