spidermonkey

Javascript var vs let (de)optimization/slowdown issue in v8 and SpiderMonkey

女生的网名这么多〃 提交于 2019-11-29 02:44:59
During JavaScript code refactoring in my project I've found that some of my loops slowed down drastically. Searching for root cause I've found this SO question stating slowdown is caused by let statement inside for loop and closure creation. To my surprise moving let and closure out of the for loop didn't help, and even using var instead of let for loop variable also does not help because slowdown is caused by let placed after the for loop. By removing extra details I've obtained this code snippet: "use strict" console.log("========================="); (function(){ var itr = 0; function f(){+

Is Javascript substring virtual?

给你一囗甜甜゛ 提交于 2019-11-29 01:31:44
If we have a huge string, named str1 , say 5 million characters long, and then str2 = str1.substr(5555, 100) so that str2 is 100 characters long and is a substring of str1 starting at 5555 (or any other randomly selected position). How JavaScript stores str2 internally? Is the string contents copied or the new string is sort of virtual and only a reference to the original string and values for position and size are stored? I know this is implementation dependent, ECMAScript standard (probably) does not define what's under the hood of the string implementation. But I want to know from some

How does event handling work internally within JavaScript?

爷,独闯天下 提交于 2019-11-28 20:47:05
Specifically Spidermonkey . I know you write functions and attach them to events to handle them. Where is the onClick handler defined and how does the JS engine know to fire onClick events when the user clicks? Any keywords, design patterns, links, etc are appreciated. UPDATE Aggregating links I find useful here: http://www.w3.org/TR/DOM-Level-2-Events/events.html https://github.com/joyent/node/blob/master/src/node_events.cc http://mxr.mozilla.org/mozilla/source/dom/src/events/nsJSEventListener.cpp SpiderMonkey itself doesn't have anything involving event handling. Events are purely a DOM

Javascript Engines Advantages

≡放荡痞女 提交于 2019-11-28 15:57:46
I am confused about JavaScript engines right now. I know that V8 was a big deal because it compiled JavaScript to native code. Then I started reading about Mozilla SpiderMonkey , which from what I understand is written in C and can compile JavaScript. So how is this different from V8 and if this is true, why does Firefox not do this? Finally, does Rhino literally compile the JavaScript to Java byte code so you would get all the speed advantages of Java? If not, why do people not run V8 when writing scripts on their desktops? There are various approaches to JavaScript execution, even when doing

Mozilla SpiderMonkey JavaScript 内核--命令参数

纵饮孤独 提交于 2019-11-28 03:08:06
命令行选项 -b 分支限制 设置 分支限制 -c 堆栈块大小 设置 堆栈块大小 -C 编译程序,并不运行。可以通过这中方式检测代码中的错误,而免去运行代码。 -e 脚本 运行声明的 脚本 , 脚本 必须是文字字符串(literal string) -f 文件名 运行文件中的JavaScript程序 -g 秒数 启动Shell后,休眠 秒数。 用于绑定debugger. -i 启用interactive模式 -j 启用跟踪(trace) JIT -m 启用方法(method) JIT -P 在文件的第一行写入"/usr/bin/env js -P",这样文件可以直接被 JavaScript 引擎解释/执行 注:适用于UNIX和Linux -s 堆栈大小 设置 堆栈大小 -v 版本号 设置使用指定版本号的JavaScript -w 启用警告(warnning)消息 -W 禁用警告(warnning)消息 -x 启用E4X XML 模式 转载于:https://www.cnblogs.com/ebread/archive/2011/07/07/2100127.html 来源: https://blog.csdn.net/weixin_30896763/article/details/99952271

Are javascript Arrays actually implemented as arrays?

微笑、不失礼 提交于 2019-11-27 22:01:43
The difference between a javascript Array , and Object is not very big. In fact it seems Array mainly adds the length field, so you can use both Array s and Object s as numeric arrays: var ar = new Array(); ar[0] = "foo"; ar["bar"] = "foo"; var ob = new Object(); ob[0] = "foo"; ob["bar"] = "foo"; assert(ar[0] == ob[0] == ar["0"] == ob["0"] == ar.bar == ob.bar); // Should be true. So my questions is, in popular javascript engines (V8, JavaScriptCore, SpiderMonkey, etc), how is this handled? Obviously we do not want our arrays to be actually stored as hash maps with key values! How can we be

How do I get console input in javascript?

被刻印的时光 ゝ 提交于 2019-11-27 19:58:01
I'm currently using spidermonkey to run my JavaScript code. I'm wondering if there's a function to get input from the console similar to how Python does this: var = raw_input() Or in C++: std::cin >> var; I've looked around and all I've found so far is how to get input from the browser using the prompt() and confirm() functions. MooGoo Good old readline(); See MDN docs: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell#readline.28.29 In plain JavaScript, simply use response = readline() after printing a prompt. In Node.js, you'll need

Does creating functions consume more memory

萝らか妹 提交于 2019-11-27 18:21:06
问题 // Case A function Constructor() { this.foo = function() { ... }; ... } // vs // Case B function Constructor() { ... }; Constructor.prototype.foo = function() { ... } One of the main reasons people advise the use of prototypes is that .foo is created once in the case of the prototype where as this.foo is created multiple times when using the other approach. However one would expect interpreters can optimize this. So that there is only one copy of the function foo in case A. Of course you

Constant declaration with block

故事扮演 提交于 2019-11-27 16:08:43
Recently I was looking into Firefox Add-on Builder SDK sources, and stumbled on such constants declaration: const { getCodeForKey, toJSON } = require("../../keyboard/utils"); I could find information about CommonJS Modules , but left part of this assignment slightly confuses me, since it must be language specific, and I couldn't google anything on that. Can someone point me to some specification/draft that explains what's going on here? This is a destructuring assignment , something that is currently only implemented by the SpiderMonkey JavaScript engine which is used by Firefox. Here is how

Will Function.prototype.bind() always be slow?

放肆的年华 提交于 2019-11-27 16:05:18
问题 I am writing an open source javascript library, and I use .bind() method heavily, because I have an idea that object-oriented code looks more clear then. ( debatable, though ) Example A1: var that = this; setTimeout(function () { that.method(); }, 0); vs B1: setTimeout(this.method.bind(this), 0); Or, a more practical code portion A2: remoteDataSource.getData(function (a, b, c, d) { obj.dataGetter(a, b, c, d); }) vs B2: remoteDataSource.getData(obj/* or prototype */.dataGetter.bind(obj)); I