代码拉取完成,页面将自动刷新
// 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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。