Repository: electron/electron
File: shell/renderer/api/electron_api_context_bridge.cc (C++)

Code before:
        blink::WebBlob::FromV8Value(destination_context->GetIsolate(), value);
    if (!blob.IsNull()) {
      v8::Context::Scope destination_context_scope(destination_context);
      return v8::MaybeLocal<v8::Value>(
          blob.ToV8Value(destination_context->GetIsolate()));
    }

    // Custom logic to "clone" FileList references
    auto object_value = value.As<v8::Object>();
    v8::Maybe<bool> has_length = object_value->Has(
        source_context,
        gin::StringToV8(source_context->GetIsolate(), "length"));
    v8::Maybe<bool> has_item = object_value->Has(
        source_context, gin::StringToV8(source_context->GetIsolate(), "item"));
    if (has_length.FromJust() && has_item.FromJust()) {
      v8::Local<v8::Value> length, item_fn;
      if (object_value
              ->Get(source_context,
                    gin::StringToV8(source_context->GetIsolate(), "length"))
              .ToLocal(&length) &&
          length->IsNumber() &&
          object_value
              ->Get(source_context,
                    gin::StringToV8(source_context->GetIsolate(), "item"))
              .ToLocal(&item_fn) &&
          item_fn->IsFunction()) {
        v8::Context::Scope destination_scope(destination_context);
        uint32_t item_count = length->Uint32Value(source_context).FromJust();
        v8::Local<v8::Array> array =
            v8::Array::New(destination_context->GetIsolate(), item_count);

        for (uint32_t i = 0; i < item_count; i++) {
          v8::Local<v8::Value> file;
          if (object_value->Get(source_context, i).ToLocal(&file)) {
            auto passed_file = PassValueToOtherContextInner(
                source_context, source_execution_context, destination_context,
                file, value, object_cache, support_dynamic_properties,
                recursion_depth + 1, error_target);

            if (!passed_file.IsEmpty() &&
                !IsTrue(array->Set(destination_context, i,
                                   passed_file.ToLocalChecked())))
              return {};
          }
        }

        object_cache->CacheProxiedObject(value, array);
        return v8::MaybeLocal<v8::Value>(array);
      }
    }
  }

Review comment (suggestion):
```suggestion
      if (object_value->Get(source_context, length_key).ToLocal(&length) &&
           length->IsNumber() &&
          object_value->Get(source_context, item_key).ToLocal(&item_fn) &&
           item_fn->IsFunction()) {
```

Code after:
        blink::WebBlob::FromV8Value(destination_context->GetIsolate(), value);
    if (!blob.IsNull()) {
      v8::Context::Scope destination_context_scope(destination_context);
      return v8::MaybeLocal<v8::Value>(
          blob.ToV8Value(destination_context->GetIsolate()));
    }
  }

  // Proxy all objects
  if (IsPlainObject(value)) {
    auto object_value = value.As<v8::Object>();
    auto passed_value = CreateProxyForAPI(
        object_value, source_context, source_execution_context,
        destination_context, object_cache, support_dynamic_properties,
        recursion_depth + 1, error_target);
    if (passed_value.IsEmpty())
      return {};
    return v8::MaybeLocal<v8::Value>(passed_value.ToLocalChecked());
  }

  // Serializable objects
  blink::CloneableMessage ret;
  {
    v8::Local<v8::Context> error_context =
        error_target == BridgeErrorTarget::kSource ? source_context
                                                   : destination_context;
    v8::Context::Scope error_scope(error_context);
    // V8 serializer will throw an error if required
    if (!gin::ConvertFromV8(error_context->GetIsolate(), value, &ret)) {
      return {};
    }
  }

  {
    v8::Context::Scope destination_context_scope(destination_context);
    v8::Local<v8::Value> cloned_value =
        gin::ConvertToV8(destination_context->GetIsolate(), ret);
    object_cache->CacheProxiedObject(value, cloned_value);
    return v8::MaybeLocal<v8::Value>(cloned_value);
  }
}

v8::MaybeLocal<v8::Value> PassValueToOtherContext(
    v8::Local<v8::Context> source_context,
    v8::Local<v8::Context> destination_context,
    v8::Local<v8::Value> value,
    v8::Local<v8::Value> parent_value,
    bool support_dynamic_properties,
    BridgeErrorTarget error_target,
    context_bridge::ObjectCache* existing_object_cache) {
  TRACE_EVENT0("electron", "ContextBridge::PassValueToOtherContext");