mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Add Object.isSealed & Object.isFrozen
This commit is contained in:
parent
2e20275e07
commit
d1d4d939ea
|
@ -144,3 +144,39 @@ func builtinObject_preventExtensions(call FunctionCall) Value {
|
|||
}
|
||||
return object
|
||||
}
|
||||
|
||||
func builtinObject_isSealed(call FunctionCall) Value {
|
||||
object := call.Argument(0)
|
||||
if object := object._object(); object != nil {
|
||||
if object.stash.extensible() {
|
||||
return toValue(false)
|
||||
}
|
||||
result := true
|
||||
object.enumerate(func(name string) {
|
||||
property := object.getProperty(name)
|
||||
if property.configurable() {
|
||||
result = false
|
||||
}
|
||||
})
|
||||
return toValue(result)
|
||||
}
|
||||
panic(newTypeError())
|
||||
}
|
||||
|
||||
func builtinObject_isFrozen(call FunctionCall) Value {
|
||||
object := call.Argument(0)
|
||||
if object := object._object(); object != nil {
|
||||
if object.stash.extensible() {
|
||||
return toValue(false)
|
||||
}
|
||||
result := true
|
||||
object.enumerate(func(name string) {
|
||||
property := object.getProperty(name)
|
||||
if property.configurable() || property.writable() {
|
||||
result = false
|
||||
}
|
||||
})
|
||||
return toValue(result)
|
||||
}
|
||||
panic(newTypeError())
|
||||
}
|
||||
|
|
|
@ -177,6 +177,8 @@ func newContext() *_runtime {
|
|||
"create", 2, builtinObject_create,
|
||||
"isExtensible", -1, builtinObject_isExtensible,
|
||||
"preventExtensions", -1, builtinObject_preventExtensions,
|
||||
"isSealed", -1, builtinObject_isSealed,
|
||||
"isFrozen", -1, builtinObject_isFrozen,
|
||||
)
|
||||
|
||||
self.Global.Function = self.newGlobalFunction(
|
||||
|
|
|
@ -108,3 +108,19 @@ func TestObject_preventExtensions(t *testing.T) {
|
|||
test(`Object.preventExtensions.length`, "1")
|
||||
test(`Object.preventExtensions.prototype`, "undefined")
|
||||
}
|
||||
|
||||
func TestObject_isSealed(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`Object.isSealed.length`, "1")
|
||||
test(`Object.isSealed.prototype`, "undefined")
|
||||
}
|
||||
|
||||
func TestObject_isFrozen(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`Object.isFrozen.length`, "1")
|
||||
test(`Object.isFrozen.prototype`, "undefined")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user