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 {
* Support for TC39 "dynamic code brand checks" proposal.
*
* 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:
Object();
......@@ -7007,14 +7007,14 @@ class V8_EXPORT ObjectTemplate : public Template {
/**
* Support for TC39 "dynamic code brand checks" proposal.
*
* This API allows to mark (& query) objects as "code kind", which causes
* them to be treated as code-like (i.e. like Strings) in the context of
* eval and function constructor.
* This API allows to mark (& query) objects as "code like", which causes
* them to be treated like Strings in the context of eval and function
* constructor.
*
* Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks
*/
void SetCodeKind();
bool IsCodeKind();
void SetCodeLike();
bool IsCodeLike();
V8_INLINE static ObjectTemplate* Cast(Data* data);
......@@ -7598,7 +7598,7 @@ typedef ModifyCodeGenerationFromStringsResult (
typedef ModifyCodeGenerationFromStringsResult (
*ModifyCodeGenerationFromStringsCallback2)(Local<Context> context,
Local<Value> source,
bool is_code_kind);
bool is_code_like);
// --- WebAssembly compilation callbacks ---
typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
......
......@@ -2005,15 +2005,15 @@ void ObjectTemplate::SetImmutableProto() {
self->set_immutable_proto(true);
}
bool ObjectTemplate::IsCodeKind() {
return Utils::OpenHandle(this)->code_kind();
bool ObjectTemplate::IsCodeLike() {
return Utils::OpenHandle(this)->code_like();
}
void ObjectTemplate::SetCodeKind() {
void ObjectTemplate::SetCodeLike() {
auto self = Utils::OpenHandle(this);
i::Isolate* isolate = self->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
self->set_code_kind(true);
self->set_code_like(true);
}
// --- S c r i p t s ---
......@@ -9212,12 +9212,12 @@ void v8::Isolate::LocaleConfigurationChangeNotification() {
#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);
LOG_API(i_isolate, Object, IsCodeKind);
LOG_API(i_isolate, Object, IsCodeLike);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::HandleScope scope(i_isolate);
return Utils::OpenHandle(this)->IsCodeKind(i_isolate);
return Utils::OpenHandle(this)->IsCodeLike(i_isolate);
}
// static
......
......@@ -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) {
if (!args.at(i + 1)->IsCodeKind(isolate)) {
is_code_kind = false;
if (!args.at(i + 1)->IsCodeLike(isolate)) {
is_code_like = false;
break;
}
}
......@@ -96,7 +96,7 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
isolate, function,
Compiler::GetFunctionFromString(
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);
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(
......
......@@ -2076,7 +2076,7 @@ bool CodeGenerationFromStringsAllowed(Isolate* isolate, Handle<Context> context,
// or v8::Isolate::SetModifyCodeGenerationFromStringsCallback2)
bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
Handle<i::Object>* source,
bool is_code_kind) {
bool is_code_like) {
DCHECK(isolate->modify_code_gen_callback() ||
isolate->modify_code_gen_callback2());
DCHECK(source);
......@@ -2092,7 +2092,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
v8::Utils::ToLocal(*source))
: isolate->modify_code_gen_callback2()(v8::Utils::ToLocal(context),
v8::Utils::ToLocal(*source),
is_code_kind);
is_code_like);
if (result.codegen_allowed && !result.modified_source.IsEmpty()) {
// Use the new source (which might be the same as the old source).
*source =
......@@ -2118,7 +2118,7 @@ bool ModifyCodeGenerationFromStrings(Isolate* isolate, Handle<Context> context,
// static
std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
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.
// 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
......@@ -2133,9 +2133,9 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
// (I.e., let allow_code_gen_callback decide, if it has been set.)
if (isolate->allow_code_gen_callback()) {
// 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.
DCHECK(!original_source->IsCodeKind(isolate));
DCHECK(!original_source->IsCodeLike(isolate));
if (!original_source->IsString()) {
return {MaybeHandle<String>(), true};
......@@ -2154,7 +2154,7 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
isolate->modify_code_gen_callback2()) {
Handle<i::Object> modified_source = original_source;
if (!ModifyCodeGenerationFromStrings(isolate, context, &modified_source,
is_code_kind)) {
is_code_like)) {
return {MaybeHandle<String>(), false};
}
if (!modified_source->IsString()) {
......@@ -2164,8 +2164,8 @@ std::pair<MaybeHandle<String>, bool> Compiler::ValidateDynamicCompilationSource(
}
if (!context->allow_code_gen_from_strings().IsFalse(isolate) &&
original_source->IsCodeKind(isolate)) {
// Codegen is unconditionally allowed, and we're been given a CodeKind
original_source->IsCodeLike(isolate)) {
// Codegen is unconditionally allowed, and we're been given a CodeLike
// object. Stringify.
MaybeHandle<String> stringified_source =
Object::ToString(isolate, original_source);
......@@ -2208,10 +2208,10 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromValidatedString(
// static
MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
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();
MaybeHandle<String> validated_source =
ValidateDynamicCompilationSource(isolate, context, source, is_code_kind)
ValidateDynamicCompilationSource(isolate, context, source, is_code_like)
.first;
return GetFunctionFromValidatedString(context, validated_source, restriction,
parameters_end_pos);
......
......@@ -142,14 +142,14 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
// Create a (bound) function for a String source within a context for eval.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromString(
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
// deal seperately with a case of object not handled by the embedder.
V8_WARN_UNUSED_RESULT static std::pair<MaybeHandle<String>, bool>
ValidateDynamicCompilationSource(Isolate* isolate, Handle<Context> context,
Handle<i::Object> source_object,
bool is_code_kind = false);
bool is_code_like = false);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction>
GetFunctionFromValidatedString(Handle<Context> context,
MaybeHandle<String> source,
......
......@@ -790,7 +790,7 @@ class RuntimeCallTimer final {
V(Object_HasRealIndexedProperty) \
V(Object_HasRealNamedCallbackProperty) \
V(Object_HasRealNamedProperty) \
V(Object_IsCodeKind) \
V(Object_IsCodeLike) \
V(Object_New) \
V(Object_ObjectProtoToString) \
V(Object_Set) \
......
......@@ -2068,7 +2068,7 @@ bool JSReceiver::HasProxyInPrototype(Isolate* isolate) {
return false;
}
bool JSReceiver::IsCodeKind(Isolate* isolate) const {
bool JSReceiver::IsCodeLike(Isolate* isolate) const {
DisallowGarbageCollection no_gc;
Object maybe_constructor = map().GetConstructor();
if (!maybe_constructor.IsJSFunction()) return false;
......@@ -2080,7 +2080,7 @@ bool JSReceiver::IsCodeKind(Isolate* isolate) const {
.get_api_func_data()
.GetInstanceTemplate();
if (instance_template.IsUndefined(isolate)) return false;
return ObjectTemplateInfo::cast(instance_template).code_kind();
return ObjectTemplateInfo::cast(instance_template).code_like();
}
// static
......
......@@ -286,7 +286,7 @@ class JSReceiver : public HeapObject {
bool HasProxyInPrototype(Isolate* isolate);
// TC39 "Dynamic Code Brand Checks"
bool IsCodeKind(Isolate* isolate) const;
bool IsCodeLike(Isolate* isolate) const;
OBJECT_CONSTRUCTORS(JSReceiver, HeapObject);
};
......
......@@ -1809,9 +1809,9 @@ bool Object::IterationHasObservableEffects() {
return true;
}
bool Object::IsCodeKind(Isolate* isolate) const {
bool Object::IsCodeLike(Isolate* isolate) const {
DisallowGarbageCollection no_gc;
return IsJSReceiver() && JSReceiver::cast(*this).IsCodeKind(isolate);
return IsJSReceiver() && JSReceiver::cast(*this).IsCodeLike(isolate);
}
void Object::ShortPrint(FILE* out) const {
......
......@@ -587,7 +587,7 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
bool IterationHasObservableEffects();
// TC39 "Dynamic Code Brand Checks"
bool IsCodeKind(Isolate* isolate) const;
bool IsCodeLike(Isolate* isolate) const;
EXPORT_DECL_VERIFIER(Object)
......
......@@ -134,12 +134,12 @@ void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
return set_data(IsImmutablePrototypeBit::update(data(), immutable));
}
bool ObjectTemplateInfo::code_kind() const {
bool ObjectTemplateInfo::code_like() const {
return IsCodeKindBit::decode(data());
}
void ObjectTemplateInfo::set_code_kind(bool is_code_kind) {
return set_data(IsCodeKindBit::update(data(), is_code_kind));
void ObjectTemplateInfo::set_code_like(bool is_code_like) {
return set_data(IsCodeKindBit::update(data(), is_code_like));
}
bool FunctionTemplateInfo::IsTemplateFor(JSObject object) {
......
......@@ -160,7 +160,7 @@ class ObjectTemplateInfo
public:
DECL_INT_ACCESSORS(embedder_field_count)
DECL_BOOLEAN_ACCESSORS(immutable_proto)
DECL_BOOLEAN_ACCESSORS(code_kind)
DECL_BOOLEAN_ACCESSORS(code_like)
// Dispatched behavior.
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