1 Star 0 Fork 0

似是故人来/v8go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
object_template.go 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
zhengkaikai 提交于 2023-05-10 19:27 . 添加转换为object template方法
// Copyright 2020 Roger Chapman and the v8go contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package v8go
// #include <stdlib.h>
// #include "v8go.h"
import "C"
import (
"errors"
)
// PropertyAttribute are the attribute flags for a property on an Object.
// Typical usage when setting an Object or TemplateObject property, and
// can also be validated when accessing a property.
type PropertyAttribute uint8
const (
// None.
None PropertyAttribute = 0
// ReadOnly, ie. not writable.
ReadOnly PropertyAttribute = 1 << iota
// DontEnum, ie. not enumerable.
DontEnum
// DontDelete, ie. not configurable.
DontDelete
)
// ObjectTemplate is used to create objects at runtime.
// Properties added to an ObjectTemplate are added to each object created from the ObjectTemplate.
type ObjectTemplate struct {
*template
}
// NewObjectTemplate creates a new ObjectTemplate.
// The *ObjectTemplate can be used as a v8go.ContextOption to create a GlobalObject object in a Context.
func NewObjectTemplate(iso *Isolate) *ObjectTemplate {
if iso == nil {
panic("nil Isolate argument not supported")
}
tmpl := &template{
ptr: C.NewObjectTemplate(iso.ptr),
iso: iso,
}
iso.templateLock.Lock()
defer iso.templateLock.Unlock()
iso.templates = append(iso.templates, tmpl)
return &ObjectTemplate{tmpl}
}
// NewInstance creates a new Object based on the template.
func (o *ObjectTemplate) NewInstance(ctx *Context) (*Object, error) {
if ctx == nil {
return nil, errors.New("v8go: Context cannot be <nil>")
}
rtn := C.ObjectTemplateNewInstance(o.ptr, ctx.ptr)
return objectResult(ctx.iso, rtn)
}
// SetInternalFieldCount sets the number of internal fields that instances of this
// template will have.
func (o *ObjectTemplate) SetInternalFieldCount(fieldCount uint32) {
C.ObjectTemplateSetInternalFieldCount(o.ptr, C.int(fieldCount))
}
// InternalFieldCount returns the number of internal fields that instances of this
// template will have.
func (o *ObjectTemplate) InternalFieldCount() uint32 {
return uint32(C.ObjectTemplateInternalFieldCount(o.ptr))
}
func (o *ObjectTemplate) apply(opts *contextOptions) {
opts.gTmpl = o
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hasika/v8go.git
[email protected]:hasika/v8go.git
hasika
v8go
v8go
master

搜索帮助