Skip to content

webkitRequestFileSystem.getFile returns NOT_FOUND_ERR #4549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DartBot opened this issue Aug 16, 2012 · 8 comments
Closed

webkitRequestFileSystem.getFile returns NOT_FOUND_ERR #4549

DartBot opened this issue Aug 16, 2012 · 8 comments
Labels
web-libraries Issues impacting dart:html, etc., libraries
Milestone

Comments

@DartBot
Copy link

DartBot commented Aug 16, 2012

This issue was originally filed by [email protected]


I'm trying to port (http://www.html5rocks.com/en/tutorials/file/filesystem/) to Dart. Things work under Dartium, but they fail when compiling to JavaScript. I think I know why.

Here's the code:

import('dart:html');

import('dart:web');

// This example leads to NOT_FOUND_ERR when using dart2js, but not when using Dartium.

bool _handleError(FileError e) {
  var msg = '';
  switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
      msg = 'QUOTA_EXCEEDED_ERR';
      break;
    case FileError.NOT_FOUND_ERR:
      msg = 'NOT_FOUND_ERR';
      break;
    case FileError.SECURITY_ERR:
      msg = 'SECURITY_ERR';
      break;
    case FileError.INVALID_MODIFICATION_ERR:
      msg = 'INVALID_MODIFICATION_ERR';
      break;
    case FileError.INVALID_STATE_ERR:
      msg = 'INVALID_STATE_ERR';
      break;
    default:
      msg = 'Unknown Error';
      break;
  }
  window.alert("Error: $msg");
  return true;
}
  
void main() {
  window.webkitRequestFileSystem(Window.TEMPORARY, 1024 * 1024, (filesystem) {
    filesystem.root.getFile('log.txt', {"create": true}, null, _handleError);
  }, _handleError);
}

Here is a snippet from the generated JavaScript:

$.$defineNativeClass('DirectoryEntry', [], {
 getFile$4: function(path, flags, successCallback, errorCallback) {
  return this.getFile(path,flags,$.convertDartClosureToJS(successCallback, 1),$.convertDartClosureToJS(errorCallback, 1));
 }
});

"this" is a "DirectoryEntry". Hence, we're calling a native JavaScript function. At this point, flags should be a normal JavaScript object, {create: true}. It isn't. It's a LinkedHashMapImplementation. Because everything is an object in JavaScript, it tries to lookup "create" on that object, and it's not actually there. Hence, rather than trying to create the object, it tries to lookup an existing file with that name, and it's not found. That's why this leads to NOT_FOUND_ERR when trying to create the file.

I'm prioritizing this as high since it's blocking my HTML5 tutorial work and since it should be straightforward to fix :)

@DartBot
Copy link
Author

DartBot commented Aug 16, 2012

This comment was originally written by [email protected]


I think the gist of the bug is that when you pass an object as an argument to a native function, you sometimes have to make sure that that object is a "plain old JavaScript object".

I say sometimes, because it depends on the function. If the function is part of a container class of sometime, it would make sense for you to be able to get back the Dart object that you gave the container object. However, in this case, the function is an HTML5 function that needs a plain old JavaScript object.

@sethladd
Copy link
Contributor

cc @rakudrama.
Removed Priority-High, Area-Dart2JS labels.
Added Priority-Medium, Area-HTML, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Aug 16, 2012

This comment was originally written by [email protected]


Extrapolating from the above comment, we're going to have to look at every parameter to every native JavaScript function to determine whether objects should be "unboxed" (i.e. translated to plain old JavaScript objects).

@vsmenon
Copy link
Member

vsmenon commented Aug 16, 2012

sra is working on general plumbing to do this sort of check.


Added this to the M1 milestone.
Marked this as being blocked by #4062.

@DartBot
Copy link
Author

DartBot commented Aug 17, 2012

This comment was originally written by [email protected]


See also issue #3022. It may be the same bug.

@rakudrama
Copy link
Member

JJ - can you try this again?
I'm hoping that r11193 + r11208 will get this going.

Unfortunately the one test we have in this area has lots of bugs of its own.

@DartBot
Copy link
Author

DartBot commented Aug 23, 2012

This comment was originally written by [email protected]


I'll work on this today.

@DartBot
Copy link
Author

DartBot commented Aug 23, 2012

This comment was originally written by [email protected]


I just tried the latest build, and it works in Dartium and dart2js! :-D

I'm marking this as verified.


Added Verified label.

@DartBot DartBot added Type-Defect web-libraries Issues impacting dart:html, etc., libraries labels Aug 23, 2012
@DartBot DartBot added this to the M1 milestone Aug 23, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

4 participants