diff --git a/builtin_object.go b/builtin_object.go index 764cc5f..d81edfb 100644 --- a/builtin_object.go +++ b/builtin_object.go @@ -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()) +} diff --git a/global.go b/global.go index d27e611..6da6676 100644 --- a/global.go +++ b/global.go @@ -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( diff --git a/object_test.go b/object_test.go index 3d9b929..043b531 100644 --- a/object_test.go +++ b/object_test.go @@ -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") +}