Skip to content

Uncaught Error: runtime error: cannot internalize time.Time from undefined, must be Date #433

Open
@oskca

Description

@oskca

I'm trying to do a gopherjs binding for VueJS. I found a clear way to do bidirectional data bindings from gopherjs to VueJS and so far it works great 😄 But I came into this problem when VueJS trying to set time.Time from javascript side to gopherjs code, error code is here: https://github.com/oskca/gopherjs-vue/blob/master/examples/unwritableTime/main.go#L20. (you can try it with gopherjs serve)

The error stack goes to $internalize, :

  var timePkg = $packages["time"];
  if (timePkg !== undefined && t === timePkg.Time) {
    if (!(v !== null && v !== undefined && v.constructor === Date)) {
      $throwRuntimeError("cannot internalize time.Time from " + typeof v + ", must be Date");
    }
    return timePkg.Unix(new $Int64(0, 0), new $Int64(0, v.getTime() * 1000000));
  }

Normal gopherjs code with time.Time works fine, but in this case VueJS probably tries to set time.Time with a function or some other customed data types.

How could this problem be solved? Isn't !(v !== null && v !== undefined && v.constructor === Date) too much restricted? What about just return time.Time{} with warning message instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions