1


When we are using Phantomjs in our project in conjunction with Base2 library, we are getting the following error:

+ phantomjs ...../src/test/javascript/SpecRunner.html
TypeError: setting a property that has only a getter

Can anyone point out how to fix this issue? It seems it occurs due to Javascript "strict mode" inside Phantomjs (refer here), but could not find from Phantomjs docs on how to turn this off, especially since it occurs in the external lib (Base2.js) that we need?

Thanks,
Paddy

Paddy
  • 2,842
  • 5
  • 26
  • 45

1 Answers1

0

Base2.js does not seem to define "use strict". This means that in one of your javascript files you have a "use strict" line outside of any function. This turns on strict mode at the point it is defined and you can not turn it off again. It is better to turn it on only inside function declarations.

To figure out this problem, search for "use strict" or 'use strict' in all files included in your project. Then remove them or move them inside function bodies.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode

Can I disable ECMAscript strict mode for specific functions?

Community
  • 1
  • 1
Nathaniel Johnson
  • 4,283
  • 1
  • 33
  • 65
  • Hi @Emmentaler, you were right, but I use lot of external libraries like angular*.js, which contain global "use strict" lines outside any function. This meant that to solve the problem using the idea you suggested, I had to not only declare base2.js before all these external JS libraries, but also the classes that extend Base2 before all these libraries that use Base2 in SpecRunner.html, which looks awkward, although you can live with it if there is no other way out. Isn't there a way to turn off "use strict" at the beginning of my files extending Base2 ? – Paddy Oct 07 '13 at 15:26
  • Alas no. It is a known issue. The problem is that it was implemented this way to retain backwards compatibility with earlier version of javascript. I hate that it doesn't work like a #define in C or C++. In the edit above I added the link to a similar SO question – Nathaniel Johnson Oct 07 '13 at 16:43
  • Thanks @Emmentaler, that means we have to live with the awkwardness of declaring all JS files that are "not strict" upfront. Since it is SpecRunner.html and not actual code, I guess it is not too much of an issue at least for now. – Paddy Oct 08 '13 at 03:34