package goja

import (
	

	
)

type objectGoMapSimple struct {
	baseObject
	data map[string]interface{}
}

func ( *objectGoMapSimple) () {
	.baseObject.init()
	.prototype = .val.runtime.global.ObjectPrototype
	.class = classObject
	.extensible = true
}

func ( *objectGoMapSimple) ( string) Value {
	,  := .data[]
	if ! {
		return nil
	}
	return .val.runtime.ToValue()
}

func ( *objectGoMapSimple) ( unistring.String,  Value) Value {
	if  := ._getStr(.String());  != nil {
		return 
	}
	return .baseObject.getStr(, )
}

func ( *objectGoMapSimple) ( unistring.String) Value {
	if  := ._getStr(.String());  != nil {
		return 
	}
	return nil
}

func ( *objectGoMapSimple) ( unistring.String,  Value,  bool) bool {
	 := .String()
	if ,  := .data[];  {
		.data[] = .Export()
		return true
	}
	if  := .prototype;  != nil {
		// we know it's foreign because prototype loops are not allowed
		if ,  := .self.setForeignStr(, , .val, );  {
			return 
		}
	}
	// new property
	if !.extensible {
		.val.runtime.typeErrorResult(, "Cannot add property %s, object is not extensible", )
		return false
	} else {
		.data[] = .Export()
	}
	return true
}

func trueValIfPresent( bool) Value {
	if  {
		return valueTrue
	}
	return nil
}

func ( *objectGoMapSimple) ( unistring.String, ,  Value,  bool) (bool, bool) {
	return ._setForeignStr(, trueValIfPresent(._hasStr(.String())), , , )
}

func ( *objectGoMapSimple) ( string) bool {
	,  := .data[]
	return 
}

func ( *objectGoMapSimple) ( unistring.String) bool {
	return ._hasStr(.String())
}

func ( *objectGoMapSimple) ( unistring.String,  PropertyDescriptor,  bool) bool {
	if !.val.runtime.checkHostObjectPropertyDescr(, , ) {
		return false
	}

	 := .String()
	if .extensible || ._hasStr() {
		.data[] = .Value.Export()
		return true
	}

	.val.runtime.typeErrorResult(, "Cannot define property %s, object is not extensible", )
	return false
}

func ( *objectGoMapSimple) ( unistring.String,  bool) bool {
	delete(.data, .String())
	return true
}

type gomapPropIter struct {
	o         *objectGoMapSimple
	propNames []string
	idx       int
}

func ( *gomapPropIter) () (propIterItem, iterNextFunc) {
	for .idx < len(.propNames) {
		 := .propNames[.idx]
		.idx++
		if ,  := .o.data[];  {
			return propIterItem{name: newStringValue(), enumerable: _ENUM_TRUE}, .
		}
	}

	return propIterItem{}, nil
}

func ( *objectGoMapSimple) () iterNextFunc {
	 := make([]string, len(.data))
	 := 0
	for  := range .data {
		[] = 
		++
	}

	return (&gomapPropIter{
		o:         ,
		propNames: ,
	}).next
}

func ( *objectGoMapSimple) ( bool,  []Value) []Value {
	// all own keys are enumerable
	for  := range .data {
		 = append(, newStringValue())
	}
	return 
}

func ( *objectGoMapSimple) (*objectExportCtx) interface{} {
	return .data
}

func ( *objectGoMapSimple) () reflect.Type {
	return reflectTypeMap
}

func ( *objectGoMapSimple) ( objectImpl) bool {
	if ,  := .(*objectGoMapSimple);  {
		return  == 
	}
	return false
}