package goja

type weakSetObject struct {
	baseObject
	s weakMap
}

func ( *weakSetObject) () {
	.baseObject.init()
	.s = weakMap(.val.runtime.genId())
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	,  := .self.(*weakSetObject)
	if ! {
		panic(.NewTypeError("Method WeakSet.prototype.add called on incompatible receiver %s", .objectproto_toString(FunctionCall{This: })))
	}
	.s.set(.toObject(.Argument(0)), nil)
	return .This
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	,  := .self.(*weakSetObject)
	if ! {
		panic(.NewTypeError("Method WeakSet.prototype.delete called on incompatible receiver %s", .objectproto_toString(FunctionCall{This: })))
	}
	,  := .Argument(0).(*Object)
	if  && .s.remove() {
		return valueTrue
	}
	return valueFalse
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	,  := .self.(*weakSetObject)
	if ! {
		panic(.NewTypeError("Method WeakSet.prototype.has called on incompatible receiver %s", .objectproto_toString(FunctionCall{This: })))
	}
	,  := .Argument(0).(*Object)
	if  && .s.has() {
		return valueTrue
	}
	return valueFalse
}

func ( *Runtime) ( []Value,  *Object) *Object {
	if  == nil {
		panic(.needNew("WeakSet"))
	}
	 := .getPrototypeFromCtor(, .global.WeakSet, .global.WeakSetPrototype)
	 := &Object{runtime: }

	 := &weakSetObject{}
	.class = classObject
	.val = 
	.extensible = true
	.self = 
	.prototype = 
	.init()
	if len() > 0 {
		if  := [0];  != nil &&  != _undefined &&  != _null {
			 := .getStr("add", nil)
			 := .checkStdArrayIter()
			if  == .global.weakSetAdder {
				if  != nil {
					for ,  := range .values {
						.s.set(.toObject(), nil)
					}
				} else {
					.getIterator(, nil).iterate(func( Value) {
						.s.set(.toObject(), nil)
					})
				}
			} else {
				 := toMethod()
				if  == nil {
					panic(.NewTypeError("WeakSet.add in missing"))
				}
				if  != nil {
					for ,  := range .values {
						(FunctionCall{This: , Arguments: []Value{}})
					}
				} else {
					.getIterator(, nil).iterate(func( Value) {
						(FunctionCall{This: , Arguments: []Value{}})
					})
				}
			}
		}
	}
	return 
}

func ( *Runtime) ( *Object) objectImpl {
	 := newBaseObjectObj(, .global.ObjectPrototype, classObject)

	._putProp("constructor", .global.WeakSet, true, false, true)
	.global.weakSetAdder = .newNativeFunc(.weakSetProto_add, "add", 1)
	._putProp("add", .global.weakSetAdder, true, false, true)
	._putProp("delete", .newNativeFunc(.weakSetProto_delete, "delete", 1), true, false, true)
	._putProp("has", .newNativeFunc(.weakSetProto_has, "has", 1), true, false, true)

	._putSym(SymToStringTag, valueProp(asciiString(classWeakSet), false, false, true))

	return 
}

func ( *Runtime) ( *Object) objectImpl {
	 := .newNativeConstructOnly(, .builtin_newWeakSet, .getWeakSetPrototype(), "WeakSet", 0)

	return 
}

func ( *Runtime) () *Object {
	 := .global.WeakSetPrototype
	if  == nil {
		 = &Object{runtime: }
		.global.WeakSetPrototype = 
		.self = .createWeakSetProto()
	}
	return 
}

func ( *Runtime) () *Object {
	 := .global.WeakSet
	if  == nil {
		 = &Object{runtime: }
		.global.WeakSet = 
		.self = .createWeakSet()
	}
	return 
}