Commit fee41d59 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[modules] Implement module namespace exotic object [[DefineOwnProperty]]

Bug: v8:12240
Change-Id: I9bf62d8c99b1f945139e274652d667c1a361e2a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3180371Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77095}
parent e5595fb9
......@@ -1055,6 +1055,11 @@ Maybe<bool> JSReceiver::DefineOwnProperty(Isolate* isolate,
return JSTypedArray::DefineOwnProperty(
isolate, Handle<JSTypedArray>::cast(object), key, desc, should_throw);
}
if (object->IsJSModuleNamespace()) {
return JSModuleNamespace::DefineOwnProperty(
isolate, Handle<JSModuleNamespace>::cast(object), key, desc,
should_throw);
}
// OrdinaryDefineOwnProperty, by virtue of calling
// DefineOwnPropertyIgnoreAttributes, can handle arguments
......
......@@ -17,6 +17,7 @@
#include "src/objects/js-generator-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/source-text-module.h"
#include "src/objects/synthetic-module-inl.h"
#include "src/utils/ostreams.h"
......@@ -427,6 +428,44 @@ Maybe<PropertyAttributes> JSModuleNamespace::GetPropertyAttributes(
return Just(it->property_attributes());
}
// ES
// https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-defineownproperty-p-desc
// static
Maybe<bool> JSModuleNamespace::DefineOwnProperty(
Isolate* isolate, Handle<JSModuleNamespace> object, Handle<Object> key,
PropertyDescriptor* desc, Maybe<ShouldThrow> should_throw) {
// 1. If Type(P) is Symbol, return OrdinaryDefineOwnProperty(O, P, Desc).
if (key->IsSymbol()) {
return OrdinaryDefineOwnProperty(isolate, object, key, desc, should_throw);
}
// 2. Let current be ? O.[[GetOwnProperty]](P).
PropertyKey lookup_key(isolate, key);
LookupIterator it(isolate, object, lookup_key, LookupIterator::OWN);
PropertyDescriptor current;
Maybe<bool> has_own = GetOwnPropertyDescriptor(&it, &current);
MAYBE_RETURN(has_own, Nothing<bool>());
// 3. If current is undefined, return false.
// 4. If Desc.[[Configurable]] is present and has value true, return false.
// 5. If Desc.[[Enumerable]] is present and has value false, return false.
// 6. If ! IsAccessorDescriptor(Desc) is true, return false.
// 7. If Desc.[[Writable]] is present and has value false, return false.
// 8. If Desc.[[Value]] is present, return
// SameValue(Desc.[[Value]], current.[[Value]]).
if (!has_own.FromJust() ||
(desc->has_configurable() && desc->configurable()) ||
(desc->has_enumerable() && !desc->enumerable()) ||
PropertyDescriptor::IsAccessorDescriptor(desc) ||
(desc->has_writable() && !desc->writable()) ||
(desc->has_value() && !desc->value()->SameValue(*current.value()))) {
RETURN_FAILURE(isolate, GetShouldThrow(isolate, should_throw),
NewTypeError(MessageTemplate::kRedefineDisallowed, key));
}
return Just(true);
}
bool Module::IsGraphAsync(Isolate* isolate) const {
DisallowGarbageCollection no_gc;
......
......@@ -160,6 +160,10 @@ class JSModuleNamespace
static V8_WARN_UNUSED_RESULT Maybe<PropertyAttributes> GetPropertyAttributes(
LookupIterator* it);
static V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
Isolate* isolate, Handle<JSModuleNamespace> o, Handle<Object> key,
PropertyDescriptor* desc, Maybe<ShouldThrow> should_throw);
// In-object fields.
enum {
kToStringTagFieldIndex,
......
......@@ -431,9 +431,6 @@
'language/statements/class/subclass/derived-class-return-override-finally-super-arrow': [FAIL],
'language/statements/class/subclass/derived-class-return-override-for-of-arrow': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=12240
'language/module-code/namespace/internals/define-own-property': [FAIL],
######################## NEEDS INVESTIGATION ###########################
# https://bugs.chromium.org/p/v8/issues/detail?id=7833
......
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