Commit 051b704a authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[runtime] Handlify Script::GetScriptHash()

Bug: v8:12965
Change-Id: I16b67335978714f05658f75f7a9a038270dbd69b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3702337
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Auto-Submit: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81138}
parent 3ff93604
......@@ -500,8 +500,9 @@ MaybeLocal<String> Script::SourceMappingURL() const {
MaybeLocal<String> Script::GetSha256Hash() const {
i::Handle<i::Script> script = Utils::OpenHandle(this);
i::Isolate* isolate = script->GetIsolate();
i::Handle<i::String> value =
script->GetScriptHash(/* forceForInspector: */ true);
i::Script::GetScriptHash(isolate, script, /* forceForInspector: */ true);
return Utils::ToLocal(value);
}
......
......@@ -206,7 +206,7 @@ Handle<String> CallSiteInfo::GetScriptHash(Handle<CallSiteInfo> info) {
return isolate->factory()->empty_string();
}
if (script->HasValidSource()) {
return script->GetScriptHash(/*forceForInspector:*/ false);
return Script::GetScriptHash(isolate, script, /*forceForInspector:*/ false);
}
return isolate->factory()->empty_string();
}
......
......@@ -5037,32 +5037,35 @@ Object Script::GetNameOrSourceURL() {
return name();
}
Handle<String> Script::GetScriptHash(bool forceForInspector) {
auto isolate = GetIsolate();
if (origin_options().IsOpaque() && !forceForInspector) {
// static
Handle<String> Script::GetScriptHash(Isolate* isolate, Handle<Script> script,
bool forceForInspector) {
if (script->origin_options().IsOpaque() && !forceForInspector) {
return isolate->factory()->empty_string();
}
Object maybe_source_hash = source_hash();
if (maybe_source_hash.IsString()) {
Handle<String> precomputed(String::cast(maybe_source_hash), isolate);
if (precomputed->length() > 0) {
return precomputed;
PtrComprCageBase cage_base(isolate);
{
Object maybe_source_hash = script->source_hash(cage_base);
if (maybe_source_hash.IsString(cage_base)) {
Handle<String> precomputed(String::cast(maybe_source_hash), isolate);
if (precomputed->length() > 0) {
return precomputed;
}
}
}
Handle<Object> src(source(), isolate);
if (!src->IsString()) {
return isolate->factory()->empty_string();
Handle<String> src_text;
{
Object maybe_script_source = script->source(cage_base);
if (!maybe_script_source.IsString(cage_base)) {
return isolate->factory()->empty_string();
}
src_text = handle(String::cast(maybe_script_source), isolate);
}
Handle<String> src_text = Handle<String>::cast(src);
char formatted_hash[kSizeOfFormattedSha256Digest];
// std::unique_ptr<UChar[]> buffer(new UChar[src->Length()]);
// int written = src->Write(isolate,
// reinterpret_cast<uint16_t*>(buffer.get()), 0, source->Length()); size_t
// writtenSizeInBytes = sizeof(UChar) * written;
std::unique_ptr<char[]> string_val = src_text->ToCString();
size_t len = strlen(string_val.get());
......@@ -5074,7 +5077,7 @@ Handle<String> Script::GetScriptHash(bool forceForInspector) {
Handle<String> result =
isolate->factory()->NewStringFromAsciiChecked(formatted_hash);
set_source_hash(*result);
script->set_source_hash(*result);
return result;
}
......
......@@ -157,7 +157,8 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
inline bool IsMaybeUnfinalized(Isolate* isolate) const;
Object GetNameOrSourceURL();
Handle<String> GetScriptHash(bool forceForInspector);
static Handle<String> GetScriptHash(Isolate* isolate, Handle<Script> script,
bool forceForInspector);
// Retrieve source position from where eval was called.
static int GetEvalPosition(Isolate* isolate, Handle<Script> script);
......
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