dart's latest js-interop library causes some issues lately - javascript

I have seen some strange changes in the latest js-interop library and I wonder if anybody can give some clarification about it.
After upgrading to the latest version I noticed dart2js doesn't work anymore. After some investigation I concluded the cause was an #proxy annotation inside the js-interop library ( also mentioned here).
Because of this I switched between a couple of versions and I noticed some functions like scoped have been deprecated in a timespan of only a couple of days after which it has been completely removed! If you missed the in between version in which this function is marked as deprecated you miss the hint which give's some info about it. Also note that the main tutorials about the js library on dartlang.org don't even give a hint about the fact that large parts of it have become outdated.
I decided to go back to version 0.0.26 and although it seemed to work as before... I noticed in one instance when retrieving a variable from the javascript context in dart I received a dart DateTime object and not a js.Proxy object.
Going back a version earlier (v0.0.25) I got back my js.Proxy when using a variable from the js context, as expected.
The weird thing is that on github the versions go until 0.0.25 (which work as expected) and the one on pub has 3 versions more, which all break backwards compatibility a lot (which sometimes is needed) without clear instructions about what is going on (which I find lightly frustrating).
Can somebody give some clarifications about what is going on and what I can expect for the coming times?
http://pub.dartlang.org/packages/js

All this breaking changes have been announced in Future breaking changes in package:js and BREAKING CHANGE: package:js deprecated features removed.
Basically, starting from 0.0.26, package:js is now baked with dart:js. This change comes with several things :
scopes/retain/release are no longer needed
several types are now transfered directly between Dart and Js and not proxied
null, bool, num, String, DateTime
Blob
KeyRange
ImageData
TypedData, including its subclasses like Int32List, but not ByteBuffer
Node
Element from shadow dom can now be transfered as well
Callback are now longer needed.
a really big performance improvement
Here's a quick migration guide :
scopes : remove js.retain, js.release and js.scoped.
replace new Callback.xxxx(f) with f and remove callback.dispose().
replace Proxy with transferable type based on the above list.

Related

"Intl not available" in Edge 15

I'm seeing an Intl not available error in the JS console when my script runs the following code in Edge 15:
new Date().toLocaleDateString()
I'm a bit stumped by this. It is working just fine in Edge 14, and I can't find any reference to the internationalization API suddenly disappearing from Edge 15.
I'm not sure if this is the proper way to test it, but running window.hasOwnProperty("Intl") in the console actually returns true. To me this seems to indicate that Intl actually is there.
Anyone with more JS skills able to tell what is really going on here?
Make sure your JS code doesn't redefine standard Map class.
We had almost the same problem, but with Intl.Collator object instead. We couldn't use String.prototype.localeCompare("...", "locale") because of this.
You can look at this codepen in Edge 15 and in other browsers for explanation: https://codepen.io/kgorob/pen/pweaWV.
P.S.
I'm not sure your problem is because of Map class specifically, maybe it's some other standard JS class you are re-defining.
The problem is because of these lines in Chakracore code. Intl.js is javascript file that is used internally to perform various internationalization specific operations. Since Mapis used, over-writing it before Intl.js code executes (it is executed lazily), causes problem. This should be addressed soon.
As ksp's answer says, this is caused by Intl lazy-loading after Map is overwritten. Therefore, the easiest workaround is to just force it to initialise early, before other scripts run:
<html>
<head>
<script>Intl.DateTimeFormat</script>
...
Here is the issue in the Chakra repo: https://github.com/Microsoft/ChakraCore/issues/3189

Knockout.js 3.4.1 throws multiple bindings error

I'm working on a rather large project where I use KnockoutJS (large as in it would be impossible to post all related code here), and today I upgraded from Knockout 3.4.0 to 3.4.1. After doing this, I am suddenly getting a multiple bindings-error on every pageload ("You cannot apply bindings multiple times to the same element").
I have been using Knockout for a while, and I am very confident that I am in no way applying bindings multiple times to the same element. I only call applybindings once, and I have confirmed that this statement also only ever runs once by debugging that code (and also searching for any other instances of this function).
After debugging this problem for I while, I decided to downgrade again, to Knockout 3.4.0. And as it turns out, the error is only showing up on the latest build, version 3.4.1.
Anyone else noticed this behaviour? What did they change to cause this?
Even when I run the debug-version of KO, the error can not tell me what element it is referring to, which makes it hopeless to figure out where the error actually comes from.
I am also not using the second optional parameter when calling applybindings (no specific element target), as I am only doing this once anyway.
5 months after your question someone raised an issue with the same problem on their Github page. It was fixed here.
Brian M Hunt's (one of the owners) comment:
The issue was that the valueAccessor() needed to be called (if it's a function) to create the dependency. I believe I have the right fix for it in TKO (basically if (typeof valueAccessor() === 'function') {valueAccessor()()} in the render loop), but the TKO fix doesn't back-port/translate directly since it's using the new binding class style.

Browser.ExecScript() stopped working after updating windows

I've set up a simple testbed for WatiN (ver 2.1) which reads:
var browser = new IE();
browser.GoTo("http://www.google.co.il"); // webpage doesn't matter really
browser.RunScript("alert(123)");
This works only if KB3025390 is not installed. Installing it breaks the above test with an UnAuthorizedAccessException which has HRESULT set to E_ACCESSDENIED. What gives? Is there any workaround?
Update: Using IWebBrowser2.Navigate2 along with "javascript:console.log(123)" type of scripts works however
it makes me feel uneasy using such a backchannel
the scripts run through this back-channel of .Navigate2() may only have a max length of about 2070 chars (give or take) otherwise they get forcibly truncated to this length leading to javascript errors upon attempting to run them
using .Navigate2(), even with the most trivial script, will clog the ready state of Internet Explorer for good in the sense that it will be set to READYSTATE_LOADING without any hope of getting rid of it. In simple terms this means that once you use this hack, you either have to perform every single subsequent operation in WatiN in a "dont-wait-for-webpage-to-load" fashion (GoToNoWait, ClickNoWait etc) lest your code freezes upon waiting for the browser to turn back to READYSTATE_COMPLETE (which will never come about ofcourse as already mentioned).
there appears to be a much broader issue here in the sense that I can't even access the properties of an IHtmlWindow2 object p.e. window.document throws an unauthorized exception again making it virtually impossible to transfer over to the C# world the return-values of the scripts I'm running (using Expando etc) for documents other than window.top.document (for the window.top.document window there is IWebBrowser2.Document which does the trick)
Update#2: The folks over at the selenium project have also noticed this issue:
https://code.google.com/p/selenium/issues/detail?id=8302
A bug report has been created as well:
https://connect.microsoft.com/IE/feedback/details/1062093/installation-of-kb3025390-breaks-out-of-process-javascript-execution-in-ie11
Update#3: IHTMLWindow2.setInterval and IHTMLWindow2.setTimeout also throw UnauthorizedAccess exceptions. These methods are not marked as deprecated in:
http://msdn.microsoft.com/ko-kr/library/windows/desktop/aa741505%28v=vs.85%29.aspx
yet they have wounded up suffering from the same cutbacks all the same.
Update#4: I gave the approach recommended in this post a shot:
https://stackoverflow.com/a/18546866/863651
In order to dynamically invoke the "eval" method of the IHTMLWindow2 object (or any other method really). Got the same "System.UnauthorizedAccessException" as above. So no joy here either.
Microsoft recommends using "eval" over "execscript" however after the above experiment I suspect that they are refering to accessing "eval" only from within the browser.
As far as I can tell thus far, when it comes to the full-fledged IE11+ using "eval" out-of-process (via COM) appears to have been completely prohibited along with any other function-invocation of the window object, the only exception being the back-channel of the .Navigate2() mentioned above.
It turns out Microsoft eventually backpedaled on its decision to kill off .execScript at COM-level. Just install the latest updates for Windows including kb3025390: One of the updates for IE that came after kb3025390 brings back .execScript functionality at COM-level
Note, however, that .execScript is not accessible through IE's javascript anymore. In that context it's gone for good.
fyi: this one is also not working
ieInstance.Document.Script.<methodNameString>(<commaSeperatedParameterString>)
try this worked for me at some places but not all places
ieObject.Navigate "javascript:<methodNameString>(<commaSeperatedParameterString>)", Null, "_parent"
or
ieObject.Navigate2 "javascript:"<methodNameString>(<commaSeperatedParameterString>)", Null, "_parent"
now trying to find out solution using eval
I have found a way around the problem of an update installing automatically. You can just create a simple batch file with following content.
{code}
#echo off
wusa /uninstall /kb:3025390/quiet /norestart
END
{code}
Then go to task scheduler, create a new task for this batch file to run every one hour or day as per your requirements. Add it as a system task so it runs in the background and does not affect the running automations.

BreezeJS RequireJS support unstable (knockout example)

As I'm trying to compile my project with breeze and requirejs for production, I'm running into multiple issues. Unrolling this, I tried starting fresh with the Knockout RequireJS example.
After I installed MVS2013Pro I was able to run the project, but not without issues:
window.breeze is defined so it has been leaked to global scope (this
should not happen with RequireJS)
Hitting F5 Refresh will crash with
Uncaught Error: Can't find breeze and/or Q (breeze savequeuing)
Uncaught TypeError: undefined is not a function (breeze dataservice)
With these errors I'm not even trying to establish my grunt requirejs (r optimizer) task. As these are the root of my problems.
Note: I'm not searching for a knockout solution, my stack actually is: MongoDataService+Breeze+SaveQueueing+RequireJS+AngularJS+Socket.IO+Cordova
window.breeze
You're right that breeze sneaks back into the browser way down at the bottom of breeze.debug.js:
if (global.window) {
global.window.breeze = breeze;
}
We don't know why we put that in the code base. No one remembers. Coming at the end as it does, it clearly isn't needed by Breeze itself.
I commented it out in preliminary testing and that seems to do the trick. The window.breeze becomes undefined in the Todo-KO-Require sample; it remains defined (properly) in samples that do not use require.js.
We don't think this would be a breaking change for anyone ... and the remedy is simple enough: define it yourself at the top of your app.
We'll probably remove these lines for the next release unless we discover a reason to do otherwise.
F5 fail?
I can't repro this at all. I suspect your are conflating your discovery that breeze is inadvertently in the global namespace with your efforts to write an Angular app that uses breeze.savequeuing.js.
Why do I think this? Because the error you describe arises when trying to use breeze.savequeuing.js in an Angular app which is explicitly disallowed in the comments (line #14) of v.1.0.4:
Depends on Breeze (which it patches) and Q.js (not for use in Angular ... yet)
You no doubt omitted Q.js from your required libraries and it all goes to custard from there.
I'm personally allergic to the "save-when-user-changes-anything" user experience that made save queuing necessary. I'm almost sorry I wrote it. But there it is.
The apparently dependence on Q.js is the reason it isn't available for Angular apps as written. It's actually pretty easy to make it Angular-ready now because we recently (quietly) made accessible the component that Breeze is using for promises
breeze.Q // returns the promises component currently used by Breeze
Therefore, you could change the one reference to Q on line #104 to
var deferredSave = breeze.Q.defer();
This should work when using breeze v.1.4.14 and later. I haven't fully tested it yet.
This change (or something like it) likely will find its way into breeze.savequeuing.js v.1.1.0 (as I just pushed a non-release version of that).

In what situation would document.open() return null?

I'm trying to understand an intermittent script error that I am seeing in a JavaScript intensive thin-client application running under Internet Explorer 6 and Windows XP. The root cause of the problem is that the following function call returns a null value (however it does succeed without an error):
var doc = targetWindow.document.open("text/html","_replace");
Where targetWindow is a window object.
Neither targetWindow nor targetWindow.document is null and so I'm struggling to understand why this call would return null. My interpretation of the documentation is that this method shouldn't ever return null.
This code has been unchanged and working perfectly for many years - until I understand why this is happening I'm not sure either how I might handle this, or what might have changed to cause this to start happening.
What might cause this function call to return null?
According to the documentation you should be passing "replace", not "_replace". Try this instead:
var doc = targetWindow.document.open("text/html", "replace");
Since you say your code has worked for years, then it is likely that something has changed and the above suggestion may not be the issue. However, it is still worth a try.
Have you changed any js files / libraries you are using in your application lately? Also, are you using any browser plugins within the page? It is possible that a newer version of either of these could be somehow affecting your call to "document.open".
document.open() does not have any parameters by W3C standard. Check out this link: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170
I recommend you to use W3C documentation instead of Microsoft's one because with W3C you are sure it works on all modern browsers, while Microsoft is well known for adding extensions that, of course, works only in their own products. It's called EEE (Embrace, extend and extinguish).
Simply use document.open() without arguments. There are ways to manipulate user history, but that's called bad programming practice. History is user's private data and web application should not try to manipulate it.

Categories

Resources