File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2639,6 +2639,10 @@ enum AccessControl {
26392639 PROHIBITS_OVERWRITING = 1 << 2
26402640};
26412641
2642+ /**
2643+ * Integrity level for objects.
2644+ */
2645+ enum class IntegrityLevel { kFrozen, kSealed };
26422646
26432647/**
26442648 * A JavaScript object (ECMA-262, 4.3.3)
@@ -2830,6 +2834,11 @@ class V8_EXPORT Object : public Value {
28302834 */
28312835 Local<String> GetConstructorName();
28322836
2837+ /**
2838+ * Sets the integrity level of the object.
2839+ */
2840+ Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
2841+
28332842 /** Gets the number of internal fields for this Object. */
28342843 int InternalFieldCount();
28352844
Original file line number Diff line number Diff line change @@ -3912,6 +3912,19 @@ Local<String> v8::Object::GetConstructorName() {
39123912 return Utils::ToLocal (name);
39133913}
39143914
3915+ Maybe<bool > v8::Object::SetIntegrityLevel (Local<Context> context,
3916+ IntegrityLevel level) {
3917+ PREPARE_FOR_EXECUTION_PRIMITIVE (context, " v8::Object::SetIntegrityLevel()" ,
3918+ bool );
3919+ auto self = Utils::OpenHandle (this );
3920+ i::JSReceiver::IntegrityLevel i_level =
3921+ level == IntegrityLevel::kFrozen ? i::FROZEN : i::SEALED;
3922+ Maybe<bool > result =
3923+ i::JSReceiver::SetIntegrityLevel (self, i_level, i::Object::DONT_THROW);
3924+ has_pending_exception = result.IsNothing ();
3925+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE (bool );
3926+ return result;
3927+ }
39153928
39163929Maybe<bool > v8::Object::Delete (Local<Context> context, Local<Value> key) {
39173930 PREPARE_FOR_EXECUTION_PRIMITIVE (context, " v8::Object::Delete()" , bool );
Original file line number Diff line number Diff line change @@ -24985,3 +24985,21 @@ TEST(MemoryPressure) {
2498524985 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone);
2498624986 CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
2498724987}
24988+
24989+ TEST(SetIntegrityLevel) {
24990+ LocalContext context;
24991+ v8::Isolate* isolate = CcTest::isolate();
24992+ v8::HandleScope scope(isolate);
24993+
24994+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
24995+ CHECK(context->Global()->Set(context.local(), v8_str("o"), obj).FromJust());
24996+
24997+ v8::Local<v8::Value> is_frozen = CompileRun("Object.isFrozen(o)");
24998+ CHECK(!is_frozen->BooleanValue(context.local()).FromJust());
24999+
25000+ CHECK(obj->SetIntegrityLevel(context.local(), v8::IntegrityLevel::kFrozen)
25001+ .FromJust());
25002+
25003+ is_frozen = CompileRun("Object.isFrozen(o)");
25004+ CHECK(is_frozen->BooleanValue(context.local()).FromJust());
25005+ }
You can’t perform that action at this time.
0 commit comments