Commit 543e5633 authored by Daniel Vogelheim's avatar Daniel Vogelheim Committed by Commit Bot

[api] TC39 Dynamic Code Brand checks - rename for consistency.

Rename-only CL: Rename "code kind" to "code like".

The reason is CL feedback when using this feature, and a desire for
consistency across V8 + Blink. An additional benefit would be to
disambiguate from the v8::internal::CodeKind type, which is unrelated to
any of this.

Original CL: crrev.com/c/v8/v8/+/2339618
CL whose review prompted this change: crrev.com/c/2340905

Bug: chromium:1096017
Change-Id: Id59016fc2906ab6cd1414e598338b3963811b92f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509598Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Daniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70970}
parent a8eea879
...@@ -4207,11 +4207,11 @@ class V8_EXPORT Object : public Value { ...@@ -4207,11 +4207,11 @@ class V8_EXPORT Object : public Value {
* Support for TC39 "dynamic code brand checks" proposal. * Support for TC39 "dynamic code brand checks" proposal.
* *
* This API allows to query whether an object was constructed from a * This API allows to query whether an object was constructed from a
* "code kind" ObjectTemplate. * "code like" ObjectTemplate.
* *
* See also: v8::ObjectTemplate::SetCodeKind * See also: v8::ObjectTemplate::SetCodeLike
*/ */
bool IsCodeKind(Isolate* isolate); bool IsCodeLike(Isolate* isolate);
private: private:
Object(); Object();
...@@ -7007,14 +7007,14 @@ class V8_EXPORT ObjectTemplate : public Template { ...@@ -7007,14 +7007,14 @@ class V8_EXPORT ObjectTemplate : public Template {
/** /**
* Support for TC39 "dynamic code brand checks" proposal. * Support for TC39 "dynamic code brand checks" proposal.
* *
* This API allows to mark (& query) objects as "code kind", which causes * This API allows to mark (& query) objects as "code like", which causes
* them to be treated as code-like (i.e. like Strings) in the context of * them to be treated like Strings in the context of eval and function
* eval and function constructor. * constructor.
* *
* Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks * Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks
*/ */
void SetCodeKind(); void SetCodeLike();
bool IsCodeKind(); bool IsCodeLike();
V8_INLINE static ObjectTemplate* Cast(Data* data); V8_INLINE static ObjectTemplate* Cast(Data* data);
...@@ -7598,7 +7598,7 @@ typedef ModifyCodeGenerationFromStringsResult ( ...@@ -7598,7 +7598,7 @@ typedef ModifyCodeGenerationFromStringsResult (
typedef ModifyCodeGenerationFromStringsResult ( typedef ModifyCodeGenerationFromStringsResult (
*ModifyCodeGenerationFromStringsCallback2)(Local<Context> context, *ModifyCodeGenerationFromStringsCallback2)(Local<Context> context,
Local<Value> source, Local<Value> source,
bool is_code_kind); bool is_code_like);
// --- WebAssembly compilation callbacks --- // --- WebAssembly compilation callbacks ---
typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&); typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
......
...@@ -2005,15 +2005,15 @@ void ObjectTemplate::SetImmutableProto() { ...@@ -2005,15 +2005,15 @@ void ObjectTemplate::SetImmutableProto() {
self->set_immutable_proto(true); self->set_immutable_proto(true);
} }
bool ObjectTemplate::IsCodeKind() { bool ObjectTemplate::IsCodeLike() {
return Utils::OpenHandle(this)->code_kind(); return Utils::OpenHandle(this)->code_like();
} }
void ObjectTemplate::SetCodeKind() { void ObjectTemplate::SetCodeLike() {
auto self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
i::Isolate* isolate = self->GetIsolate(); i::Isolate* isolate = self->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
self->set_code_kind(true); self->set_code_like(true);
} }
// --- S c r i p t s --- // --- S c r i p t s ---
...@@ -9212,12 +9212,12 @@ void v8::Isolate::LocaleConfigurationChangeNotification() { ...@@ -9212,12 +9212,12 @@ void v8::Isolate::LocaleConfigurationChangeNotification() {
#endif // V8_INTL_SUPPORT #endif // V8_INTL_SUPPORT
} }
bool v8::Object::IsCodeKind(v8::Isolate* isolate) { bool v8::Object::IsCodeLike(v8::Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, Object, IsCodeKind); LOG_API(i_isolate, Object, IsCodeLike);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::HandleScope scope(i_isolate); i::HandleScope scope(i_isolate);
return Utils::OpenHandle(this)->IsCodeKind(i_isolate); return Utils::OpenHandle(this)->IsCodeLike(i_isolate);
} }
// static // static
......
...@@ -80,10 +80,10 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate, ...@@ -80,10 +80,10 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
} }
} }
bool is_code_kind = true; bool is_code_like = true;
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
if (!args.at(i + 1)->IsCodeKind(isolate)) { if (!args.at(i + 1)->IsCodeLike(isolate)) {
is_code_kind = false; is_code_like = false;
break; break;
} }
} }
...@@ -96,7 +96,7 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate, ...@@ -96,7 +96,7 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
isolate, function, isolate, function,
Compiler::GetFunctionFromString( Compiler::GetFunctionFromString(
handle(target->native_context(), isolate), source, handle(target->native_context(), isolate), source,
ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos, is_code_kind), ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos, is_code_like),
Object); Object);
Handle<Object> result; Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
......
...@@ -2076,7 +2076,7 @@ bool CodeGenerationFromStringsAllowed(Isolate* isolate, Handle<Context> context, ...@@ -2076,7 +2076,7 @@ bool CodeGenerationFromStringsAllowed(Isolate* isolate, Handle<Context> context,
// or v8::Isolate::SetModifyCodeGenerationFromStringsCallback2) // or v8::Isolate::SetModifyCodeGenerationFromStringsCallback2)
bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context, bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
Handle<i::Object>* source, Handle<i::Object>* source,
bool is_code_kind) { bool is_code_like) {
DCHECK(isolate->modify_code_gen_callback() || DCHECK(isolate->modify_code_gen_callback() ||
isolate->modify_code_gen_callback2()); isolate->modify_code_gen_callback2());
DCHECK(source); DCHECK(source);
...@@ -2092,7 +2092,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context, ...@@ -2092,7 +2092,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
v8::Utils::ToLocal(*source)) v8::Utils::ToLocal(*source))
: isolate->modify_code_gen_callback2()(v8::Utils::ToLocal(context), : isolate->modify_code_gen_callback2()(v8::Utils::ToLocal(context),
v8::Utils::ToLocal(*source), v8::Utils::ToLocal(*source),
is_code_kind); is_code_like);
if (result.codegen_allowed && !result.modified_source.IsEmpty()) { if (result.codegen_allowed && !result.modified_source.IsEmpty()) {
// Use the new source (which might be the same as the old source). // Use the new source (which might be the same as the old source).
*source = *source =
...@@ -2118,7 +2118,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context, ...@@ -2118,7 +2118,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
// static // static
std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource( std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
Isolate* isolate, Handle<Context> context, Isolate* isolate, Handle<Context> context,
Handle<i::Object> original_source, bool is_code_kind) { Handle<i::Object> original_source, bool is_code_like) {
// Check if the context unconditionally allows code gen from strings. // Check if the context unconditionally allows code gen from strings.
// allow_code_gen_from_strings can be many things, so we'll always check // allow_code_gen_from_strings can be many things, so we'll always check
// against the 'false' literal, so that e.g. undefined and 'true' are treated // against the 'false' literal, so that e.g. undefined and 'true' are treated
...@@ -2133,9 +2133,9 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource( ...@@ -2133,9 +2133,9 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
// (I.e., let allow_code_gen_callback decide, if it has been set.) // (I.e., let allow_code_gen_callback decide, if it has been set.)
if (isolate->allow_code_gen_callback()) { if (isolate->allow_code_gen_callback()) {
// If we run into this condition, the embedder has marked some object // If we run into this condition, the embedder has marked some object
// templates as "code kind", but has given us a callback that only accepts // templates as "code like", but has given us a callback that only accepts
// strings. That makes no sense. // strings. That makes no sense.
DCHECK(!original_source->IsCodeKind(isolate)); DCHECK(!original_source->IsCodeLike(isolate));
if (!original_source->IsString()) { if (!original_source->IsString()) {
return {MaybeHandle<String>(), true}; return {MaybeHandle<String>(), true};
...@@ -2154,7 +2154,7 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource( ...@@ -2154,7 +2154,7 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
isolate->modify_code_gen_callback2()) { isolate->modify_code_gen_callback2()) {
Handle<i::Object> modified_source = original_source; Handle<i::Object> modified_source = original_source;
if (!ModifyCodeGenerationFromStrings(isolate, context, &modified_source, if (!ModifyCodeGenerationFromStrings(isolate, context, &modified_source,
is_code_kind)) { is_code_like)) {
return {MaybeHandle<String>(), false}; return {MaybeHandle<String>(), false};
} }
if (!modified_source->IsString()) { if (!modified_source->IsString()) {
...@@ -2164,8 +2164,8 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource( ...@@ -2164,8 +2164,8 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
} }
if (!context->allow_code_gen_from_strings().IsFalse(isolate) && if (!context->allow_code_gen_from_strings().IsFalse(isolate) &&
original_source->IsCodeKind(isolate)) { original_source->IsCodeLike(isolate)) {
// Codegen is unconditionally allowed, and we're been given a CodeKind // Codegen is unconditionally allowed, and we're been given a CodeLike
// object. Stringify. // object. Stringify.
MaybeHandle<String> stringified_source = MaybeHandle<String> stringified_source =
Object::ToString(isolate, original_source); Object::ToString(isolate, original_source);
...@@ -2208,10 +2208,10 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromValidatedString( ...@@ -2208,10 +2208,10 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromValidatedString(
// static // static
MaybeHandle<JSFunction> Compiler::GetFunctionFromString( MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
Handle<Context> context, Handle<Object> source, Handle<Context> context, Handle<Object> source,
ParseRestriction restriction, int parameters_end_pos, bool is_code_kind) { ParseRestriction restriction, int parameters_end_pos, bool is_code_like) {
Isolate* const isolate = context->GetIsolate(); Isolate* const isolate = context->GetIsolate();
MaybeHandle<String> validated_source = MaybeHandle<String> validated_source =
ValidateDynamicCompilationSource(isolate, context, source, is_code_kind) ValidateDynamicCompilationSource(isolate, context, source, is_code_like)
.first; .first;
return GetFunctionFromValidatedString(context, validated_source, restriction, return GetFunctionFromValidatedString(context, validated_source, restriction,
parameters_end_pos); parameters_end_pos);
......
...@@ -142,14 +142,14 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic { ...@@ -142,14 +142,14 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
// Create a (bound) function for a String source within a context for eval. // Create a (bound) function for a String source within a context for eval.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromString( V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromString(
Handle<Context> context, Handle<i::Object> source, Handle<Context> context, Handle<i::Object> source,
ParseRestriction restriction, int parameters_end_pos, bool is_code_kind); ParseRestriction restriction, int parameters_end_pos, bool is_code_like);
// Decompose GetFunctionFromString into two functions, to allow callers to // Decompose GetFunctionFromString into two functions, to allow callers to
// deal seperately with a case of object not handled by the embedder. // deal seperately with a case of object not handled by the embedder.
V8_WARN_UNUSED_RESULT static std::pair<MaybeHandle<String>, bool> V8_WARN_UNUSED_RESULT static std::pair<MaybeHandle<String>, bool>
ValidateDynamicCompilationSource(Isolate* isolate, Handle<Context> context, ValidateDynamicCompilationSource(Isolate* isolate, Handle<Context> context,
Handle<i::Object> source_object, Handle<i::Object> source_object,
bool is_code_kind = false); bool is_code_like = false);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction>
GetFunctionFromValidatedString(Handle<Context> context, GetFunctionFromValidatedString(Handle<Context> context,
MaybeHandle<String> source, MaybeHandle<String> source,
......
...@@ -790,7 +790,7 @@ class RuntimeCallTimer final { ...@@ -790,7 +790,7 @@ class RuntimeCallTimer final {
V(Object_HasRealIndexedProperty) \ V(Object_HasRealIndexedProperty) \
V(Object_HasRealNamedCallbackProperty) \ V(Object_HasRealNamedCallbackProperty) \
V(Object_HasRealNamedProperty) \ V(Object_HasRealNamedProperty) \
V(Object_IsCodeKind) \ V(Object_IsCodeLike) \
V(Object_New) \ V(Object_New) \
V(Object_ObjectProtoToString) \ V(Object_ObjectProtoToString) \
V(Object_Set) \ V(Object_Set) \
......
...@@ -2068,7 +2068,7 @@ bool JSReceiver::HasProxyInPrototype(Isolate* isolate) { ...@@ -2068,7 +2068,7 @@ bool JSReceiver::HasProxyInPrototype(Isolate* isolate) {
return false; return false;
} }
bool JSReceiver::IsCodeKind(Isolate* isolate) const { bool JSReceiver::IsCodeLike(Isolate* isolate) const {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
Object maybe_constructor = map().GetConstructor(); Object maybe_constructor = map().GetConstructor();
if (!maybe_constructor.IsJSFunction()) return false; if (!maybe_constructor.IsJSFunction()) return false;
...@@ -2080,7 +2080,7 @@ bool JSReceiver::IsCodeKind(Isolate* isolate) const { ...@@ -2080,7 +2080,7 @@ bool JSReceiver::IsCodeKind(Isolate* isolate) const {
.get_api_func_data() .get_api_func_data()
.GetInstanceTemplate(); .GetInstanceTemplate();
if (instance_template.IsUndefined(isolate)) return false; if (instance_template.IsUndefined(isolate)) return false;
return ObjectTemplateInfo::cast(instance_template).code_kind(); return ObjectTemplateInfo::cast(instance_template).code_like();
} }
// static // static
......
...@@ -286,7 +286,7 @@ class JSReceiver : public HeapObject { ...@@ -286,7 +286,7 @@ class JSReceiver : public HeapObject {
bool HasProxyInPrototype(Isolate* isolate); bool HasProxyInPrototype(Isolate* isolate);
// TC39 "Dynamic Code Brand Checks" // TC39 "Dynamic Code Brand Checks"
bool IsCodeKind(Isolate* isolate) const; bool IsCodeLike(Isolate* isolate) const;
OBJECT_CONSTRUCTORS(JSReceiver, HeapObject); OBJECT_CONSTRUCTORS(JSReceiver, HeapObject);
}; };
......
...@@ -1809,9 +1809,9 @@ bool Object::IterationHasObservableEffects() { ...@@ -1809,9 +1809,9 @@ bool Object::IterationHasObservableEffects() {
return true; return true;
} }
bool Object::IsCodeKind(Isolate* isolate) const { bool Object::IsCodeLike(Isolate* isolate) const {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
return IsJSReceiver() && JSReceiver::cast(*this).IsCodeKind(isolate); return IsJSReceiver() && JSReceiver::cast(*this).IsCodeLike(isolate);
} }
void Object::ShortPrint(FILE* out) const { void Object::ShortPrint(FILE* out) const {
......
...@@ -587,7 +587,7 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> { ...@@ -587,7 +587,7 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
bool IterationHasObservableEffects(); bool IterationHasObservableEffects();
// TC39 "Dynamic Code Brand Checks" // TC39 "Dynamic Code Brand Checks"
bool IsCodeKind(Isolate* isolate) const; bool IsCodeLike(Isolate* isolate) const;
EXPORT_DECL_VERIFIER(Object) EXPORT_DECL_VERIFIER(Object)
......
...@@ -134,12 +134,12 @@ void ObjectTemplateInfo::set_immutable_proto(bool immutable) { ...@@ -134,12 +134,12 @@ void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
return set_data(IsImmutablePrototypeBit::update(data(), immutable)); return set_data(IsImmutablePrototypeBit::update(data(), immutable));
} }
bool ObjectTemplateInfo::code_kind() const { bool ObjectTemplateInfo::code_like() const {
return IsCodeKindBit::decode(data()); return IsCodeKindBit::decode(data());
} }
void ObjectTemplateInfo::set_code_kind(bool is_code_kind) { void ObjectTemplateInfo::set_code_like(bool is_code_like) {
return set_data(IsCodeKindBit::update(data(), is_code_kind)); return set_data(IsCodeKindBit::update(data(), is_code_like));
} }
bool FunctionTemplateInfo::IsTemplateFor(JSObject object) { bool FunctionTemplateInfo::IsTemplateFor(JSObject object) {
......
...@@ -160,7 +160,7 @@ class ObjectTemplateInfo ...@@ -160,7 +160,7 @@ class ObjectTemplateInfo
public: public:
DECL_INT_ACCESSORS(embedder_field_count) DECL_INT_ACCESSORS(embedder_field_count)
DECL_BOOLEAN_ACCESSORS(immutable_proto) DECL_BOOLEAN_ACCESSORS(immutable_proto)
DECL_BOOLEAN_ACCESSORS(code_kind) DECL_BOOLEAN_ACCESSORS(code_like)
// Dispatched behavior. // Dispatched behavior.
DECL_PRINTER(ObjectTemplateInfo) DECL_PRINTER(ObjectTemplateInfo)
......
This diff is collapsed.
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