Commit 93c60dca authored by jochen's avatar jochen Committed by Commit bot

[api] Expose ES6 7.3.14 SetIntegrityLevel on v8::Object

BUG=v8:4846
R=verwaest@chromium.org
LOG=y

Review URL: https://codereview.chromium.org/1889903003

Cr-Commit-Position: refs/heads/master@{#35520}
parent 5f5a3282
......@@ -2639,6 +2639,10 @@ enum AccessControl {
PROHIBITS_OVERWRITING = 1 << 2
};
/**
* Integrity level for objects.
*/
enum class IntegrityLevel { kFrozen, kSealed };
/**
* A JavaScript object (ECMA-262, 4.3.3)
......@@ -2830,6 +2834,11 @@ class V8_EXPORT Object : public Value {
*/
Local<String> GetConstructorName();
/**
* Sets the integrity level of the object.
*/
Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
/** Gets the number of internal fields for this Object. */
int InternalFieldCount();
......
......@@ -3912,6 +3912,19 @@ Local<String> v8::Object::GetConstructorName() {
return Utils::ToLocal(name);
}
Maybe<bool> v8::Object::SetIntegrityLevel(Local<Context> context,
IntegrityLevel level) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::SetIntegrityLevel()",
bool);
auto self = Utils::OpenHandle(this);
i::JSReceiver::IntegrityLevel i_level =
level == IntegrityLevel::kFrozen ? i::FROZEN : i::SEALED;
Maybe<bool> result =
i::JSReceiver::SetIntegrityLevel(self, i_level, i::Object::DONT_THROW);
has_pending_exception = result.IsNothing();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return result;
}
Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Delete()", bool);
......
......@@ -24985,3 +24985,21 @@ TEST(MemoryPressure) {
isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone);
CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
}
TEST(SetIntegrityLevel) {
LocalContext context;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Object> obj = v8::Object::New(isolate);
CHECK(context->Global()->Set(context.local(), v8_str("o"), obj).FromJust());
v8::Local<v8::Value> is_frozen = CompileRun("Object.isFrozen(o)");
CHECK(!is_frozen->BooleanValue(context.local()).FromJust());
CHECK(obj->SetIntegrityLevel(context.local(), v8::IntegrityLevel::kFrozen)
.FromJust());
is_frozen = CompileRun("Object.isFrozen(o)");
CHECK(is_frozen->BooleanValue(context.local()).FromJust());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment