1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +08:00

Allow (internal) enumeration through _every_ Object property

For .freeze, .isFrozen, etc.
This commit is contained in:
Robert Krimen
2013-06-02 15:21:25 -07:00
parent baf3318f30
commit 7ff3e8668e
11 changed files with 34 additions and 22 deletions

View File

@@ -98,7 +98,7 @@ func builtinObject_defineProperties(call FunctionCall) Value {
}
properties := call.runtime.toObject(call.Argument(1))
properties.enumerate(func(name string) {
properties.enumerate(true, func(name string) {
descriptor := toPropertyDescriptor(properties.get(name))
object.defineOwnProperty(name, descriptor, true)
})
@@ -118,7 +118,7 @@ func builtinObject_create(call FunctionCall) Value {
propertiesValue := call.Argument(1)
if propertiesValue.IsDefined() {
properties := call.runtime.toObject(propertiesValue)
properties.enumerate(func(name string) {
properties.enumerate(true, func(name string) {
descriptor := toPropertyDescriptor(properties.get(name))
object.defineOwnProperty(name, descriptor, true)
})
@@ -152,7 +152,7 @@ func builtinObject_isSealed(call FunctionCall) Value {
return toValue(false)
}
result := true
object.enumerate(func(name string) {
object.enumerate(true, func(name string) {
property := object.getProperty(name)
if property.configurable() {
result = false
@@ -166,7 +166,7 @@ func builtinObject_isSealed(call FunctionCall) Value {
func builtinObject_seal(call FunctionCall) Value {
object := call.Argument(0)
if object := object._object(); object != nil {
object.enumerate(func(name string) {
object.enumerate(true, func(name string) {
if property := object.getOwnProperty(name); nil != property && property.configurable() {
property.configureOff()
object.defineOwnProperty(name, *property, true)
@@ -186,7 +186,7 @@ func builtinObject_isFrozen(call FunctionCall) Value {
return toValue(false)
}
result := true
object.enumerate(func(name string) {
object.enumerate(true, func(name string) {
property := object.getProperty(name)
if property.configurable() || property.writable() {
result = false
@@ -200,7 +200,7 @@ func builtinObject_isFrozen(call FunctionCall) Value {
func builtinObject_freeze(call FunctionCall) Value {
object := call.Argument(0)
if object := object._object(); object != nil {
object.enumerate(func(name string) {
object.enumerate(true, func(name string) {
if property, update := object.getOwnProperty(name), false; nil != property {
if property.isDataDescriptor() && property.writable() {
property.writeOff()