本文整理汇总了Golang中github.com/gopherjs/gopherjs/js.InternalObject函数的典型用法代码示例。如果您正苦于以下问题:Golang InternalObject函数的具体用法?Golang InternalObject怎么用?Golang InternalObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InternalObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MakeFunc
func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
if typ.Kind() != Func {
panic("reflect: call of MakeFunc with non-Func type")
}
t := typ.common()
ftyp := (*funcType)(unsafe.Pointer(t))
fv := func() js.Object {
args := make([]Value, ftyp.NumIn())
for i := range args {
argType := ftyp.In(i).common()
args[i] = makeValue(argType, js.Arguments[i], 0)
}
resultsSlice := fn(args)
switch ftyp.NumOut() {
case 0:
return nil
case 1:
return js.InternalObject(resultsSlice[0].iword())
default:
results := js.Global.Get("Array").New(ftyp.NumOut())
for i, r := range resultsSlice {
results.SetIndex(i, js.InternalObject(r.iword()))
}
return results
}
}
return Value{t, unsafe.Pointer(js.InternalObject(fv).Unsafe()), 0, flag(Func) << flagKindShift}
}
示例2: Slice3
func (v Value) Slice3(i, j, k int) Value {
var (
cap int
typ Type
s js.Object
)
switch kind := v.kind(); kind {
case Array:
if v.flag&flagAddr == 0 {
panic("reflect.Value.Slice: slice of unaddressable array")
}
tt := (*arrayType)(unsafe.Pointer(v.typ))
cap = int(tt.len)
typ = SliceOf(tt.elem)
s = jsType(typ).New(js.InternalObject(v.iword()))
case Slice:
typ = v.typ
s = js.InternalObject(v.iword())
cap = s.Get("$capacity").Int()
default:
panic(&ValueError{"reflect.Value.Slice3", kind})
}
if i < 0 || j < i || k < j || k > cap {
panic("reflect.Value.Slice3: slice index out of bounds")
}
return makeValue(typ, js.Global.Call("$subslice", s, i, j, k), v.flag&flagRO)
}
示例3: object
func (v Value) object() *js.Object {
if v.typ.Kind() == Array || v.typ.Kind() == Struct {
return js.InternalObject(v.ptr)
}
if v.flag&flagIndir != 0 {
val := js.InternalObject(v.ptr).Call("$get")
if val != js.Global.Get("$ifaceNil") && val.Get("constructor") != jsType(v.typ) {
switch v.typ.Kind() {
case Uint64, Int64:
val = jsType(v.typ).New(val.Get("$high"), val.Get("$low"))
case Complex64, Complex128:
val = jsType(v.typ).New(val.Get("$real"), val.Get("$imag"))
case Slice:
if val == val.Get("constructor").Get("nil") {
val = jsType(v.typ).Get("nil")
break
}
newVal := jsType(v.typ).New(val.Get("$array"))
newVal.Set("$offset", val.Get("$offset"))
newVal.Set("$length", val.Get("$length"))
newVal.Set("$capacity", val.Get("$capacity"))
val = newVal
}
}
return js.InternalObject(val.Unsafe())
}
return js.InternalObject(v.ptr)
}
示例4: Read
func (r *rngReader) Read(b []byte) (n int, err error) {
array := js.InternalObject(b).Get("$array")
offset := js.InternalObject(b).Get("$offset").Int()
// browser
crypto := js.Global.Get("crypto")
if crypto == js.Undefined {
crypto = js.Global.Get("msCrypto")
}
if crypto != js.Undefined {
if crypto.Get("getRandomValues") != js.Undefined {
n = len(b)
if n > 65536 {
// Avoid QuotaExceededError thrown by getRandomValues
// when length is more than 65536, as specified in
// http://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
n = 65536
}
crypto.Call("getRandomValues", array.Call("subarray", offset, offset+n))
return n, nil
}
}
// Node.js
if require := js.Global.Get("require"); require != js.Undefined {
if randomBytes := require.Invoke("crypto").Get("randomBytes"); randomBytes != js.Undefined {
array.Call("set", randomBytes.Invoke(len(b)), offset)
return len(b), nil
}
}
return 0, errors.New("crypto/rand not available in this environment")
}
示例5: Copy
func Copy(dst, src Value) int {
dk := dst.kind()
if dk != Array && dk != Slice {
panic(&ValueError{"reflect.Copy", dk})
}
if dk == Array {
dst.mustBeAssignable()
}
dst.mustBeExported()
sk := src.kind()
if sk != Array && sk != Slice {
panic(&ValueError{"reflect.Copy", sk})
}
src.mustBeExported()
typesMustMatch("reflect.Copy", dst.typ.Elem(), src.typ.Elem())
dstVal := js.InternalObject(dst.iword())
if dk == Array {
dstVal = jsType(SliceOf(dst.typ.Elem())).New(dstVal)
}
srcVal := js.InternalObject(src.iword())
if sk == Array {
srcVal = jsType(SliceOf(src.typ.Elem())).New(srcVal)
}
return js.Global.Call("$copySlice", dstVal, srcVal).Int()
}
示例6: zeroVal
func zeroVal(typ Type) js.Object {
switch typ.Kind() {
case Bool:
return js.InternalObject(false)
case Int, Int8, Int16, Int32, Uint, Uint8, Uint16, Uint32, Uintptr, Float32, Float64:
return js.InternalObject(0)
case Int64, Uint64, Complex64, Complex128:
return jsType(typ).New(0, 0)
case Array:
elemType := typ.Elem()
return js.Global.Call("go$makeNativeArray", jsType(elemType).Get("kind"), typ.Len(), func() js.Object { return zeroVal(elemType) })
case Func:
return js.Global.Get("go$throwNilPointerError")
case Interface:
return nil
case Map:
return js.InternalObject(false)
case Chan, Ptr, Slice:
return jsType(typ).Get("nil")
case String:
return js.InternalObject("")
case Struct:
return jsType(typ).Get("Ptr").New()
default:
panic(&ValueError{"reflect.Zero", typ.Kind()})
}
}
示例7: mapdelete
func mapdelete(t *rtype, m unsafe.Pointer, key unsafe.Pointer) {
k := js.InternalObject(key).Call("$get")
if !k.Get("$key").IsUndefined() {
k = k.Call("$key")
}
js.InternalObject(m).Delete(k.Str())
}
示例8: mapaccess
func mapaccess(t *rtype, m, key unsafe.Pointer) unsafe.Pointer {
k := jsType(t.Key()).Call("keyFor", js.InternalObject(key).Call("$get")).String()
entry := js.InternalObject(m).Get(k)
if entry == js.Undefined {
return nil
}
return unsafe.Pointer(js.Global.Call("$newDataPointer", entry.Get("v"), jsType(PtrTo(t.Elem()))).Unsafe())
}
示例9: Main2
func Main2(pkgPath string, dir string, names []string, tests []func(*T)) {
flag.Parse()
if len(tests) == 0 {
fmt.Println("testing: warning: no tests to run")
}
d, err := os.Open(dir)
if err != nil {
panic(err)
}
d.Chdir()
ok := true
start := time.Now()
for i := 0; i < len(tests); i++ {
t := &T{
common: common{
start: time.Now(),
},
name: names[i],
}
t.self = t
if *chatty {
fmt.Printf("=== RUN %s\n", t.name)
}
err := runTest.Invoke(js.InternalObject(tests[i]), js.InternalObject(t))
js.Global.Set("$jsErr", nil)
if err != nil {
switch {
case !err.Get("$exit").IsUndefined():
// test failed or skipped
err = nil
case !err.Get("$notSupported").IsUndefined():
t.log(err.Get("message").Str())
t.skip()
err = nil
default:
t.Fail()
}
}
t.common.duration = time.Now().Sub(t.common.start)
t.report()
if err != nil {
throw.Invoke(js.InternalObject(err))
}
ok = ok && !t.common.failed
}
duration := time.Now().Sub(start)
status := "ok "
exitCode := 0
if !ok {
status = "FAIL"
exitCode = 1
}
fmt.Printf("%s\t%s\t%.3fs\n", status, pkgPath, duration.Seconds())
os.Exit(exitCode)
}
示例10: Store
func (v *Value) Store(x interface{}) {
if x == nil {
panic("sync/atomic: store of nil value into Value")
}
if v.v != nil && js.InternalObject(x).Get("constructor") != js.InternalObject(v.v).Get("constructor") {
panic("sync/atomic: store of inconsistently typed value into Value")
}
v.v = x
}
示例11: ValueOf
func ValueOf(i interface{}) Value {
if i == nil {
return Value{}
}
c := js.InternalObject(i).Get("constructor")
if c.Get("kind").IsUndefined() { // js.Object
return Value{jsObject(), nil, js.InternalObject(i).Unsafe(), flag(Interface) << flagKindShift}
}
return makeValue(reflectType(c), js.InternalObject(i).Get("$val"), 0)
}
示例12: mapaccess
func mapaccess(t *rtype, m, key unsafe.Pointer) unsafe.Pointer {
k := js.InternalObject(key)
if !k.Get("$key").IsUndefined() {
k = k.Call("$key")
}
entry := js.InternalObject(m).Get(k.Str())
if entry.IsUndefined() {
return nil
}
return makePointer(t.Elem(), entry.Get("v"))
}
示例13: mapaccess
func mapaccess(t *rtype, m, key unsafe.Pointer) unsafe.Pointer {
k := js.InternalObject(key).Call("$get")
if !k.Get("$key").IsUndefined() {
k = k.Call("$key")
}
entry := js.InternalObject(m).Get(k.Str())
if entry.IsUndefined() {
return nil
}
return unsafe.Pointer(js.Global.Call("$newDataPointer", entry.Get("v"), jsType(PtrTo(t.Elem()))).Unsafe())
}
示例14: mapaccess
func mapaccess(t *rtype, m iword, key iword) (val iword, ok bool) {
k := js.InternalObject(key)
if !k.Get("go$key").IsUndefined() {
k = k.Call("go$key")
}
entry := js.InternalObject(m).Get(k.Str())
if entry.IsUndefined() {
return nil, false
}
return makeIword(t.Elem(), entry.Get("v")), true
}
示例15: chansend
func chansend(t *rtype, ch unsafe.Pointer, val unsafe.Pointer, nb bool) bool {
comms := [][]interface{}{{js.InternalObject(ch), js.InternalObject(val).Call("$get")}}
if nb {
comms = append(comms, []interface{}{})
}
selectRes := selectHelper(comms)
if nb && selectRes.Index(0).Int() == 1 {
return false
}
return true
}