• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang js.InternalObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gopherjs/gopherjs/js.InternalObject函数的典型用法代码示例。如果您正苦于以下问题:Golang InternalObject函数的具体用法?Golang InternalObject怎么用?Golang InternalObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了InternalObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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}
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:31,代码来源:reflect.go


示例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)
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:31,代码来源:reflect.go


示例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)
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:28,代码来源:reflect.go


示例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")
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:33,代码来源:rand.go


示例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()
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:30,代码来源:reflect.go


示例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()})
	}
}
开发者ID:hajimehoshi,项目名称:gopherjs,代码行数:27,代码来源:reflect.go


示例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())
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:7,代码来源:reflect.go


示例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())
}
开发者ID:wmydz1,项目名称:gopherjs,代码行数:8,代码来源:reflect.go


示例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)
}
开发者ID:phaikawl,项目名称:gopherjs,代码行数:58,代码来源:testing.go


示例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
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:9,代码来源:atomic.go


示例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)
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:10,代码来源:reflect.go


示例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"))
}
开发者ID:phaikawl,项目名称:gopherjs,代码行数:11,代码来源:reflect13.go


示例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())
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:11,代码来源:reflect.go


示例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
}
开发者ID:hajimehoshi,项目名称:gopherjs,代码行数:11,代码来源:reflect.go


示例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
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:11,代码来源:reflect.go


示例16: makeMethodValue

func makeMethodValue(op string, v Value) Value {
	if v.flag&flagMethod == 0 {
		panic("reflect: internal error: invalid use of makePartialFunc")
	}

	_, fn, rcvr := methodReceiver(op, v, int(v.flag)>>flagMethodShift)
	fv := func() js.Object {
		return js.InternalObject(fn).Call("apply", rcvr, js.Arguments)
	}
	return Value{v.Type().common(), unsafe.Pointer(js.InternalObject(fv).Unsafe()), v.flag&flagRO | flag(Func)<<flagKindShift}
}
开发者ID:hajimehoshi,项目名称:gopherjs,代码行数:11,代码来源:reflect.go


示例17: DeepEqual

func DeepEqual(a1, a2 interface{}) bool {
	i1 := js.InternalObject(a1)
	i2 := js.InternalObject(a2)
	if i1 == i2 {
		return true
	}
	if i1 == nil || i2 == nil || i1.Get("constructor") != i2.Get("constructor") {
		return false
	}
	return deepValueEqualJs(ValueOf(a1), ValueOf(a2), nil)
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:11,代码来源:reflect.go


示例18: Len

func (v Value) Len() int {
	switch k := v.kind(); k {
	case Array, Slice, String:
		return js.InternalObject(v.iword()).Length()
	// case Chan:
	// 	return chanlen(v.iword())
	case Map:
		return js.Global.Call("$keys", js.InternalObject(v.iword())).Length()
	default:
		panic(&ValueError{"reflect.Value.Len", k})
	}
}
开发者ID:phaikawl,项目名称:gopherjs,代码行数:12,代码来源:reflect.go


示例19: Index

func (v Value) Index(i int) Value {
	switch k := v.kind(); k {
	case Array:
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		if i < 0 || i > int(tt.len) {
			panic("reflect: array index out of range")
		}
		typ := tt.elem
		fl := v.flag & (flagRO | flagIndir | flagAddr)
		fl |= flag(typ.Kind())

		a := js.InternalObject(v.ptr)
		if fl&flagIndir != 0 && typ.Kind() != Array && typ.Kind() != Struct {
			return Value{typ, unsafe.Pointer(jsType(PtrTo(typ)).New(
				js.InternalObject(func() *js.Object { return wrapJsObject(typ, a.Index(i)) }),
				js.InternalObject(func(x *js.Object) { a.SetIndex(i, unwrapJsObject(typ, x)) }),
			).Unsafe()), fl}
		}
		return makeValue(typ, wrapJsObject(typ, a.Index(i)), fl)

	case Slice:
		s := v.object()
		if i < 0 || i >= s.Get("$length").Int() {
			panic("reflect: slice index out of range")
		}
		tt := (*sliceType)(unsafe.Pointer(v.typ))
		typ := tt.elem
		fl := flagAddr | flagIndir | v.flag&flagRO
		fl |= flag(typ.Kind())

		i += s.Get("$offset").Int()
		a := s.Get("$array")
		if fl&flagIndir != 0 && typ.Kind() != Array && typ.Kind() != Struct {
			return Value{typ, unsafe.Pointer(jsType(PtrTo(typ)).New(
				js.InternalObject(func() *js.Object { return wrapJsObject(typ, a.Index(i)) }),
				js.InternalObject(func(x *js.Object) { a.SetIndex(i, unwrapJsObject(typ, x)) }),
			).Unsafe()), fl}
		}
		return makeValue(typ, wrapJsObject(typ, a.Index(i)), fl)

	case String:
		str := *(*string)(v.ptr)
		if i < 0 || i >= len(str) {
			panic("reflect: string index out of range")
		}
		fl := v.flag&flagRO | flag(Uint8)
		c := str[i]
		return Value{uint8Type, unsafe.Pointer(&c), fl | flagIndir}

	default:
		panic(&ValueError{"reflect.Value.Index", k})
	}
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:53,代码来源:reflect.go


示例20: chanrecv

func chanrecv(t *rtype, ch unsafe.Pointer, nb bool, val unsafe.Pointer) (selected, received bool) {
	comms := [][]interface{}{{js.InternalObject(ch)}}
	if nb {
		comms = append(comms, []interface{}{})
	}
	selectRes := selectHelper(comms)
	if nb && selectRes.Index(0).Int() == 1 {
		return false, false
	}
	recvRes := selectRes.Index(1)
	js.InternalObject(val).Call("$set", recvRes.Index(0))
	return true, recvRes.Index(1).Bool()
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:13,代码来源:reflect.go



注:本文中的github.com/gopherjs/gopherjs/js.InternalObject函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang js.MakeWrapper函数代码示例发布时间:2022-05-23
下一篇:
Golang typesutil.IsJsPackage函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap