Skip to content
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

dart:dom indexeddb idbcursorwithvalue does not have continueFunction method #1814

Closed
sethladd opened this issue Feb 23, 2012 · 13 comments
Closed
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@sethladd
Copy link
Contributor

This is an unfortunate blocker.

IDBCursorWithValue (specified http://www.w3.org/TR/IndexedDB/#idl-def-IDBCursorWithValue) should extend IDBCursor.

The current dart:dom implementation does NOT extend IDBCursor, and therefore does NOT allow a user to call continueFunction()

@sethladd
Copy link
Contributor Author

Apologies, it does extend _IDBCursorJs

However, the error I get from running a simple app is:

Uncaught TypeError: Object #<IDBCursorWithValue> has no method 'continueFunction'

@sethladd
Copy link
Contributor Author

Changed the title to: "dart:dom indexeddb idbcursorwithvalue does not have continueFunction method".

@sethladd
Copy link
Contributor Author

Sample IndexedDB code (this encounters the error): https://gist.github.com/1889118

displayItems(dom.IDBDatabase db) {
  dom.IDBTransaction txn = db.transaction(TODOS_STORE, dom.IDBTransaction.READ_ONLY);
  dom.IDBObjectStore objectStore = txn.objectStore(TODOS_STORE);
  dom.IDBRequest cursorRequest = objectStore.openCursor();
  cursorRequest.addEventListener("success", (e) {
    dom.IDBCursor cursor = e.target.result;
    if (cursor != null) {
      renderItem(cursor.value);
      cursor.continueFunction();
    }
  });
  cursorRequest.addEventListener('error', (e) {
    print("Could not open cursor: $e");
  });
}

@sethladd
Copy link
Contributor Author

Here is the compiled JavaScript code (from the nightly Frog)

cursorRequest.addEventListener("success", $wrap_call$1((function (e) {
    var cursor = e.get$target().get$result();
    if (cursor != null) {
      renderItem(cursor.value);
      cursor.continueFunction();
    }
  })

You can the continueFunction isn't being translated to .continue()

@rakudrama
Copy link
Member

This is my favourite function!

The wrapperless implementations are dropping the renaming of this special case on the floor. In the wrapping dom we had to generate cursor['continue'] since some JS implementations think that continue is a keyword.

Several things need to line up to get this to work. It is made more tricky because of the optional argument.

Option (1) is (1a) to implement 'renaming' i.e. teach Frog that lone identifiers in native strings are the real name

  void continueFunction([_IDBKeyJs key = null]) native 'continue';

(1b) teach Frog that some names need to be quoted and put in array syntax
(1c) make the generator spit out the identifier

Option (2) is to cruft up the generator with a table of a dozen or so native strings as replacements to the default action. We would generate

  void continueFunction([_IDBKeyJs key = null]) native '''
if (key == null) return this'continue';
return this'continue';
''';

I want to look more into option (1) since the compiler has much more information and the feature has other uses.

@DartBot
Copy link

DartBot commented Feb 23, 2012

This comment was originally written by ngeoffray@google.com


Stephen, I think I'd favor option 2 to go with frog, but we definitely need something different for leg.

I think generating something like (that could even be a helper);
void continueFunction([key]) {
  Function f = JS("this['continue']");
  return key == null ? f(key) : f();
}

The compiler will have enough information to optimize that.

WDYT?

@sethladd
Copy link
Contributor Author

Sounds like option 2 is under our control, and could get us over the hump. I'm concerned that option 1 would take too long.

@sethladd
Copy link
Contributor Author

Looks like the new changes aren't being copied into the SDK's lib directory. I still see:

void continueFunction([_IDBKeyJs key = null]) native;

in ~/Code/Dart-git/dart/xcodebuild/Release_ia32/dart-sdk/lib/

However, when I deleted the Release_ia32/dart-sdk directory, and rebuilt with ./tools/build.py -m release

and rebuilt, I saw the changes. I think this is a separate bug for build process.

@sethladd
Copy link
Contributor Author

Slight issue, if you have the following line of code:

dom.IDBCursorWithValue cursor = ...
cursor.continueFunction()

then the JavaScript is still cursor.continueFunction()

If you write:

var cursor = ...
cursor.continueFunction()

you will get:

cursor.continueFunction$0(); (which is correct)

Shouldn't IDBCursorWithValue work, as it extends IDBCursor?

@sethladd
Copy link
Contributor Author

BTW, success! [once I deleted and rebuilt my SDK and changed to IDBCursor] Thanks!

@rakudrama
Copy link
Member

Does the code from the first example in comment #­9 run?
cursor.continueFunction() should be fine as there should be definition of continueFunction (no $0) in the JS somewhere.

@sethladd
Copy link
Contributor Author

Yes, it does, thanks Stephen. Both 'var cursor' and 'dom.IDBCursorWithValue cursor' work. This is great, thanks! I think we can close this.

@rakudrama
Copy link
Member

Fixed. Code on github compiles and runs in unchecked mode.


Added Fixed label.

@sethladd sethladd added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures labels Apr 12, 2012
copybara-service bot pushed a commit that referenced this issue Dec 12, 2022
Revisions updated by `dart tools/rev_sdk_deps.dart`.

intl (https://github.com/dart-lang/intl/compare/a127902..881e53e):
  881e53e  Fri Dec 9 08:01:26 2022 -0800  Copybara-Service  Merge pull request #346 from lukepighetti:patch-1
  e5ca40d  Fri Dec 9 07:00:14 2022 -0800  Copybara-Service  Merge pull request #453 from selcukguvel:doc-fix
  edbfc06  Fri Dec 9 15:34:30 2022 +0100  Moritz  Merge branch 'master' into patch-1
  b489fdd  Fri Dec 9 15:30:23 2022 +0100  Moritz  Merge branch 'master' into doc-fix
  60a0d8c  Fri Dec 9 04:17:04 2022 -0800  Googler  Internal change
  ef953fd  Mon Mar 7 16:30:31 2022 +0300  selcukguvel  Fix NumberFormat document readability issue - Show "var eurosInUSFormat = .." on a new line
  aa98b67  Tue Dec 29 15:31:53 2020 -0500  Luke Pighetti  Remove 7 year old unimplemented fields

test (https://github.com/dart-lang/test/compare/73cd754..09fb067):
  09fb0679  Thu Dec 8 14:52:33 2022 -0800  Jacob MacDonald  prep packages for publishing (#1814)
  c8ac4382  Thu Dec 8 14:07:05 2022 -0800  Jacob MacDonald  Prepare for Dart 3.0 api removals (#1812)

Change-Id: I9a7caed3165d3b65e96001aa029602a09355bce8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274542
Auto-Submit: Michael Thomsen <mit@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

3 participants