Refine the type of Context to NativeContext around JSObject
This updates the type of contexts to NativeContext instead of Context, namely on GetFunctionRealm(), GetCreationContext(), and JSGlobalObject::native_context. They should be semantically NativeContexts, but the return type hides the underlying NativeContext, and causes its user to cast the context to native. Change-Id: I2f234b0df8c2dcaeab25cb543e09d80d12ca7369 Reviewed-on: https://chromium-review.googlesource.com/c/1469541 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Taiju Tsuiki <tzik@chromium.org> Cr-Commit-Position: refs/heads/master@{#59543}
This commit is contained in:
parent
8bf60985da
commit
2497023acb
@ -4845,7 +4845,8 @@ Local<v8::Object> v8::Object::Clone() {
|
|||||||
|
|
||||||
Local<v8::Context> v8::Object::CreationContext() {
|
Local<v8::Context> v8::Object::CreationContext() {
|
||||||
auto self = Utils::OpenHandle(this);
|
auto self = Utils::OpenHandle(this);
|
||||||
return Utils::ToLocal(self->GetCreationContext());
|
i::Handle<i::Context> context = self->GetCreationContext();
|
||||||
|
return Utils::ToLocal(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -565,6 +565,7 @@ class MessageLocation;
|
|||||||
class ModuleScope;
|
class ModuleScope;
|
||||||
class Name;
|
class Name;
|
||||||
class NameDictionary;
|
class NameDictionary;
|
||||||
|
class NativeContext;
|
||||||
class NewSpace;
|
class NewSpace;
|
||||||
class NewLargeObjectSpace;
|
class NewLargeObjectSpace;
|
||||||
class NumberDictionary;
|
class NumberDictionary;
|
||||||
|
@ -3126,11 +3126,12 @@ MaybeHandle<JSProxy> JSProxy::New(Isolate* isolate, Handle<Object> target,
|
|||||||
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
MaybeHandle<Context> JSProxy::GetFunctionRealm(Handle<JSProxy> proxy) {
|
MaybeHandle<NativeContext> JSProxy::GetFunctionRealm(Handle<JSProxy> proxy) {
|
||||||
DCHECK(proxy->map()->is_constructor());
|
DCHECK(proxy->map()->is_constructor());
|
||||||
if (proxy->IsRevoked()) {
|
if (proxy->IsRevoked()) {
|
||||||
THROW_NEW_ERROR(proxy->GetIsolate(),
|
THROW_NEW_ERROR(proxy->GetIsolate(),
|
||||||
NewTypeError(MessageTemplate::kProxyRevoked), Context);
|
NewTypeError(MessageTemplate::kProxyRevoked),
|
||||||
|
NativeContext);
|
||||||
}
|
}
|
||||||
Handle<JSReceiver> target(JSReceiver::cast(proxy->target()),
|
Handle<JSReceiver> target(JSReceiver::cast(proxy->target()),
|
||||||
proxy->GetIsolate());
|
proxy->GetIsolate());
|
||||||
|
@ -464,7 +464,7 @@ ACCESSORS(JSBoundFunction, bound_arguments, FixedArray, kBoundArgumentsOffset)
|
|||||||
|
|
||||||
ACCESSORS(JSFunction, raw_feedback_cell, FeedbackCell, kFeedbackCellOffset)
|
ACCESSORS(JSFunction, raw_feedback_cell, FeedbackCell, kFeedbackCellOffset)
|
||||||
|
|
||||||
ACCESSORS(JSGlobalObject, native_context, Context, kNativeContextOffset)
|
ACCESSORS(JSGlobalObject, native_context, NativeContext, kNativeContextOffset)
|
||||||
ACCESSORS(JSGlobalObject, global_proxy, JSObject, kGlobalProxyOffset)
|
ACCESSORS(JSGlobalObject, global_proxy, JSObject, kGlobalProxyOffset)
|
||||||
|
|
||||||
ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset)
|
ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset)
|
||||||
@ -604,7 +604,9 @@ bool JSFunction::has_context() const {
|
|||||||
|
|
||||||
JSGlobalProxy JSFunction::global_proxy() { return context()->global_proxy(); }
|
JSGlobalProxy JSFunction::global_proxy() { return context()->global_proxy(); }
|
||||||
|
|
||||||
Context JSFunction::native_context() { return context()->native_context(); }
|
NativeContext JSFunction::native_context() {
|
||||||
|
return context()->native_context();
|
||||||
|
}
|
||||||
|
|
||||||
void JSFunction::set_context(Object value) {
|
void JSFunction::set_context(Object value) {
|
||||||
DCHECK(value->IsUndefined() || value->IsContext());
|
DCHECK(value->IsUndefined() || value->IsContext());
|
||||||
|
@ -476,7 +476,7 @@ Handle<String> JSReceiver::GetConstructorName(Handle<JSReceiver> receiver) {
|
|||||||
return GetConstructorHelper(receiver).second;
|
return GetConstructorHelper(receiver).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<Context> JSReceiver::GetCreationContext() {
|
Handle<NativeContext> JSReceiver::GetCreationContext() {
|
||||||
JSReceiver receiver = *this;
|
JSReceiver receiver = *this;
|
||||||
// Externals are JSObjects with null as a constructor.
|
// Externals are JSObjects with null as a constructor.
|
||||||
DCHECK(!receiver->IsExternal(GetIsolate()));
|
DCHECK(!receiver->IsExternal(GetIsolate()));
|
||||||
@ -486,7 +486,7 @@ Handle<Context> JSReceiver::GetCreationContext() {
|
|||||||
function = JSFunction::cast(constructor);
|
function = JSFunction::cast(constructor);
|
||||||
} else if (constructor->IsFunctionTemplateInfo()) {
|
} else if (constructor->IsFunctionTemplateInfo()) {
|
||||||
// Remote objects don't have a creation context.
|
// Remote objects don't have a creation context.
|
||||||
return Handle<Context>::null();
|
return Handle<NativeContext>::null();
|
||||||
} else if (receiver->IsJSGeneratorObject()) {
|
} else if (receiver->IsJSGeneratorObject()) {
|
||||||
function = JSGeneratorObject::cast(receiver)->function();
|
function = JSGeneratorObject::cast(receiver)->function();
|
||||||
} else {
|
} else {
|
||||||
@ -497,13 +497,14 @@ Handle<Context> JSReceiver::GetCreationContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return function->has_context()
|
return function->has_context()
|
||||||
? Handle<Context>(function->context()->native_context(),
|
? Handle<NativeContext>(function->context()->native_context(),
|
||||||
receiver->GetIsolate())
|
receiver->GetIsolate())
|
||||||
: Handle<Context>::null();
|
: Handle<NativeContext>::null();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
MaybeHandle<Context> JSReceiver::GetFunctionRealm(Handle<JSReceiver> receiver) {
|
MaybeHandle<NativeContext> JSReceiver::GetFunctionRealm(
|
||||||
|
Handle<JSReceiver> receiver) {
|
||||||
if (receiver->IsJSProxy()) {
|
if (receiver->IsJSProxy()) {
|
||||||
return JSProxy::GetFunctionRealm(Handle<JSProxy>::cast(receiver));
|
return JSProxy::GetFunctionRealm(Handle<JSProxy>::cast(receiver));
|
||||||
}
|
}
|
||||||
@ -3001,7 +3002,7 @@ Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
MaybeHandle<Context> JSObject::GetFunctionRealm(Handle<JSObject> object) {
|
MaybeHandle<NativeContext> JSObject::GetFunctionRealm(Handle<JSObject> object) {
|
||||||
DCHECK(object->map()->is_constructor());
|
DCHECK(object->map()->is_constructor());
|
||||||
DCHECK(!object->IsJSFunction());
|
DCHECK(!object->IsJSFunction());
|
||||||
return object->GetCreationContext();
|
return object->GetCreationContext();
|
||||||
@ -4767,7 +4768,7 @@ bool JSObject::IsDroppableApiWrapper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
MaybeHandle<Context> JSBoundFunction::GetFunctionRealm(
|
MaybeHandle<NativeContext> JSBoundFunction::GetFunctionRealm(
|
||||||
Handle<JSBoundFunction> function) {
|
Handle<JSBoundFunction> function) {
|
||||||
DCHECK(function->map()->is_constructor());
|
DCHECK(function->map()->is_constructor());
|
||||||
return JSReceiver::GetFunctionRealm(
|
return JSReceiver::GetFunctionRealm(
|
||||||
@ -4863,7 +4864,8 @@ Maybe<int> JSFunction::GetLength(Isolate* isolate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Handle<Context> JSFunction::GetFunctionRealm(Handle<JSFunction> function) {
|
Handle<NativeContext> JSFunction::GetFunctionRealm(
|
||||||
|
Handle<JSFunction> function) {
|
||||||
DCHECK(function->map()->is_constructor());
|
DCHECK(function->map()->is_constructor());
|
||||||
return handle(function->context()->native_context(), function->GetIsolate());
|
return handle(function->context()->native_context(), function->GetIsolate());
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,8 @@ class JSReceiver : public HeapObject {
|
|||||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> OrdinaryToPrimitive(
|
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> OrdinaryToPrimitive(
|
||||||
Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint);
|
Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint);
|
||||||
|
|
||||||
static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver);
|
static MaybeHandle<NativeContext> GetFunctionRealm(
|
||||||
|
Handle<JSReceiver> receiver);
|
||||||
|
|
||||||
// Get the first non-hidden prototype.
|
// Get the first non-hidden prototype.
|
||||||
static inline MaybeHandle<Object> GetPrototype(Isolate* isolate,
|
static inline MaybeHandle<Object> GetPrototype(Isolate* isolate,
|
||||||
@ -203,7 +204,7 @@ class JSReceiver : public HeapObject {
|
|||||||
// function that was used to instantiate the object).
|
// function that was used to instantiate the object).
|
||||||
static Handle<String> GetConstructorName(Handle<JSReceiver> receiver);
|
static Handle<String> GetConstructorName(Handle<JSReceiver> receiver);
|
||||||
|
|
||||||
Handle<Context> GetCreationContext();
|
Handle<NativeContext> GetCreationContext();
|
||||||
|
|
||||||
V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
|
V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
|
||||||
GetPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
|
GetPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
|
||||||
@ -281,7 +282,7 @@ class JSObject : public JSReceiver {
|
|||||||
Handle<JSFunction> constructor, Handle<JSReceiver> new_target,
|
Handle<JSFunction> constructor, Handle<JSReceiver> new_target,
|
||||||
Handle<AllocationSite> site);
|
Handle<AllocationSite> site);
|
||||||
|
|
||||||
static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object);
|
static MaybeHandle<NativeContext> GetFunctionRealm(Handle<JSObject> object);
|
||||||
|
|
||||||
// 9.1.12 ObjectCreate ( proto [ , internalSlotsList ] )
|
// 9.1.12 ObjectCreate ( proto [ , internalSlotsList ] )
|
||||||
// Notice: This is NOT 19.1.2.2 Object.create ( O, Properties )
|
// Notice: This is NOT 19.1.2.2 Object.create ( O, Properties )
|
||||||
@ -921,7 +922,7 @@ class JSBoundFunction : public JSObject {
|
|||||||
Handle<JSBoundFunction> function);
|
Handle<JSBoundFunction> function);
|
||||||
static Maybe<int> GetLength(Isolate* isolate,
|
static Maybe<int> GetLength(Isolate* isolate,
|
||||||
Handle<JSBoundFunction> function);
|
Handle<JSBoundFunction> function);
|
||||||
static MaybeHandle<Context> GetFunctionRealm(
|
static MaybeHandle<NativeContext> GetFunctionRealm(
|
||||||
Handle<JSBoundFunction> function);
|
Handle<JSBoundFunction> function);
|
||||||
|
|
||||||
DECL_CAST(JSBoundFunction)
|
DECL_CAST(JSBoundFunction)
|
||||||
@ -960,11 +961,11 @@ class JSFunction : public JSObject {
|
|||||||
inline bool has_context() const;
|
inline bool has_context() const;
|
||||||
inline void set_context(Object context);
|
inline void set_context(Object context);
|
||||||
inline JSGlobalProxy global_proxy();
|
inline JSGlobalProxy global_proxy();
|
||||||
inline Context native_context();
|
inline NativeContext native_context();
|
||||||
|
|
||||||
static Handle<Object> GetName(Isolate* isolate, Handle<JSFunction> function);
|
static Handle<Object> GetName(Isolate* isolate, Handle<JSFunction> function);
|
||||||
static Maybe<int> GetLength(Isolate* isolate, Handle<JSFunction> function);
|
static Maybe<int> GetLength(Isolate* isolate, Handle<JSFunction> function);
|
||||||
static Handle<Context> GetFunctionRealm(Handle<JSFunction> function);
|
static Handle<NativeContext> GetFunctionRealm(Handle<JSFunction> function);
|
||||||
|
|
||||||
// [code]: The generated code object for this function. Executed
|
// [code]: The generated code object for this function. Executed
|
||||||
// when the function is invoked, e.g. foo() or new foo(). See
|
// when the function is invoked, e.g. foo() or new foo(). See
|
||||||
@ -1173,7 +1174,7 @@ class JSGlobalProxy : public JSObject {
|
|||||||
class JSGlobalObject : public JSObject {
|
class JSGlobalObject : public JSObject {
|
||||||
public:
|
public:
|
||||||
// [native context]: the natives corresponding to this global object.
|
// [native context]: the natives corresponding to this global object.
|
||||||
DECL_ACCESSORS(native_context, Context)
|
DECL_ACCESSORS(native_context, NativeContext)
|
||||||
|
|
||||||
// [global proxy]: the global proxy object of the context
|
// [global proxy]: the global proxy object of the context
|
||||||
DECL_ACCESSORS(global_proxy, JSObject)
|
DECL_ACCESSORS(global_proxy, JSObject)
|
||||||
|
@ -25,7 +25,7 @@ class JSProxy : public JSReceiver {
|
|||||||
// [target]: The target property.
|
// [target]: The target property.
|
||||||
DECL_ACCESSORS(target, Object)
|
DECL_ACCESSORS(target, Object)
|
||||||
|
|
||||||
static MaybeHandle<Context> GetFunctionRealm(Handle<JSProxy> proxy);
|
static MaybeHandle<NativeContext> GetFunctionRealm(Handle<JSProxy> proxy);
|
||||||
|
|
||||||
DECL_CAST(JSProxy)
|
DECL_CAST(JSProxy)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user