@@ -100,7 +100,7 @@ func callBack(ctx context.Context, o caller, method string, args ...interface{})
100100
101101// AllDBs returns the list of all existing (undeleted) databases.
102102func (p * PouchDB ) AllDBs (ctx context.Context ) ([]string , error ) {
103- if jsbuiltin .TypeOf (p .Get ("allDbs" )) != "function" {
103+ if jsbuiltin .TypeOf (p .Get ("allDbs" )) != jsbuiltin . TypeFunction {
104104 return nil , errors .New ("pouchdb-all-dbs plugin not loaded" )
105105 }
106106 result , err := callBack (ctx , p , "allDbs" )
@@ -290,8 +290,13 @@ func attachmentObject(contentType string, content io.Reader) (att *js.Object, er
290290 if _ , err := buf .ReadFrom (content ); err != nil {
291291 return nil , err
292292 }
293- if buffer := js .Global .Get ("Buffer" ); jsbuiltin .TypeOf (buffer ) == "function" {
293+ if buffer := js .Global .Get ("Buffer" ); jsbuiltin .TypeOf (buffer ) == jsbuiltin . TypeFunction {
294294 // The Buffer type is supported, so we'll use that
295+ if jsbuiltin .TypeOf (buffer .Get ("from" )) == jsbuiltin .TypeFunction {
296+ // For newer versions of Node.js. See https://nodejs.org/fa/docs/guides/buffer-constructor-deprecation/
297+ return buffer .Call ("from" , buf .String ()), nil
298+ }
299+ // Fall back to legacy Buffer constructor.
295300 return buffer .New (buf .String ()), nil
296301 }
297302 if js .Global .Get ("Blob" ) != js .Undefined {
0 commit comments