[英]How JavaScript is Executed in Google V8 specially Canvas related code
guru我正在努力了解Google-V8引擎的工作情況,據我了解,我在https://developers.google.com/v8/get_started上進行了調查,V8將javascript作為輸入,然后編譯它並獲得輸出,如上例所示,我們將其作為字符串輸出。 在現實生活場景中,考慮到這個畫布代碼,情況就不同了
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"), // Create canvas context
W = window.innerWidth, // Window's width
H = window.innerHeight, // Window's height
particles = [], // Array containing particles
ball = {}, // Ball object
paddles = [2], // Array containing two paddles
mouse = {}, // Mouse object to store it's current position
points = 0, // Varialbe to store points
fps = 60, // Max FPS (frames per second)
particlesCount = 20, // Number of sparks when ball strikes the paddle
flag = 0, // Flag variable which is changed on collision
particlePos = {}, // Object to contain the position of collision
multipler = 1, // Varialbe to control the direction of sparks
startBtn = {}, // Start button object
restartBtn = {}, // Restart button object
over = 0, // flag varialbe, cahnged when the game is over
init, // variable to initialize animation
paddleHit;
// Add mousemove and mousedown events to the canvas
canvas.addEventListener("mousemove", trackPosition, true);
canvas.addEventListener("mousedown", btnClick, true);
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
return window.setTimeout(callback, 1000 / 60);
};
})();
這些代碼是如何在V8中執行的,特別是canvas.addEventListener,它們可以粉碎一些光並幫助我理解它。
v8是可嵌入的JavaScript引擎。 此引擎與Canvas,getElement或任何其他特定於瀏覽器的功能無關。 v8將回調一個瀏覽器代碼,從你的javascript代碼中做一些事情。 您提到的鏈接是如何開始將v8嵌入到C ++應用程序中的文檔。 這樣您就可以使用JavaScript控制自己的應用程序資源。 您可以控制的資源是您的資源,文件或圖形或窗口或設備和小工具。
還有另一個項目結合了v8的強大功能和HTML渲染引擎,這個項目叫做Chromium瀏覽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.