Browse Source

Allow extracting of the sync. function callback to make the sync. call not inject the callback.

Edward Lee 15 years ago
parent
commit
f8bd77382b
2 changed files with 17 additions and 0 deletions
  1. 7 0
      Sync.js
  2. 10 0
      test/unit/test_Sync.js

+ 7 - 0
Sync.js

@@ -92,6 +92,13 @@ function syncBind(thisArg) {
     return retval;
   };
 
+  // Grabbing the onComplete converts the sync. function to not assume the first
+  // argument is our custom callback
+  syncFunc.__defineGetter__("onComplete", function() {
+    insertCallback = false;
+    return onComplete;
+  });
+
   return syncFunc;
 }
 

+ 10 - 0
test/unit/test_Sync.js

@@ -63,6 +63,16 @@ function test_Sync_sync_bind() {
   do_check_true(duration >= 100);
 }
 
+// Check that sync. function callbacks can be extracted
+function test_Function_prototype_sync_onComplete() {
+  let add = slowAdd.sync;
+  let duration = time(function() {
+    let sum = add(add.onComplete, 100, 1000, 234);
+    do_check_eq(sum, 1234);
+  });
+  do_check_true(duration >= 100);
+}
+
 // Make sure the exported Sync object/function has Function properties
 function test_function_Sync() {
   // We can't check the functions directly because the Function object for Sync