Skip to content

Instantly share code, notes, and snippets.

View tetsuharuohzeki's full-sized avatar

Tetsuharu Ohzeki tetsuharuohzeki

  • Tokyo, Japan
  • 07:40 (UTC +09:00)
View GitHub Profile
@tetsuharuohzeki
tetsuharuohzeki / sasuoni.js
Last active August 29, 2015 14:07
hubot用さすおにコマンド. BSDライセンスで良いよね
// Description
// さすおに
// http://mahouka.jp/special/#s07
//
// Configuration:
// None
//
// Commands:
var help = function () {
var text =
@tetsuharuohzeki
tetsuharuohzeki / memo.md
Last active October 26, 2015 03:24
https://github.com/Matt-Esch/virtual-dom のコードを読んだ時のメモ

revision

virtual-dom

  • 特に何も無い
  • 依存するモジュールの関数を引きずり出しているだけ
  • virtual-dom/hは例外で、与えた引数からVNodeを作る為のラッパー
@tetsuharuohzeki
tetsuharuohzeki / safe-parse.js
Last active August 29, 2015 14:05
DOMParser/DOMImplementation.createHTMLDocumentで安全なDOMの構築. とりあえずPrestoでは使えないし、IE8も確かダメ。
"use strict";
// MIT License
// author: Tetsuharu OHZEKI
/*
* Parse from HTML text to DOM subtree which does not have scripting items.
*
* @param {string} aText
* @return {DocumentFragment}
@tetsuharuohzeki
tetsuharuohzeki / draft-extact-rooting.md
Last active August 29, 2015 14:02
The draft of additional description about exact gc rooting

The following part will be added to https://github.com/mozilla/servo/wiki/Garbage-collected-DOM

——————————

Interact with Exact GC’s rooting

For supporting SpiderMonkey’s exact GC’s rooting, we introduce some types:

  • JS<T> is used for the DOM typed field in a DOM type structure. GC can trace them recursively while enclosing DOM object (maybe root) is alive.
  • Temporary<T> will used as a return value of functions returning DOM type. They are rooted while they are alive. But a retun value gets moved around. It’s breakable for the LIFO ordering constraint. Thus we need introduce Root<T>.
  • Root contains JSObject which the represented DOM type has. SpiderMonkey's conservative stack scanner will scan its JSObject and mark it as GC root.
<html>
<head>
<title>starting title</title>
</head>
<body>
<script>
var element = document.createElement("div");
// setup
for (var i = 0; i < 1000; ++i) {
var val = String( Math.random() );
"use strict";
var TrieTree = function () {
this._root = new TrieNode(undefined);
Object.freeze(this);
};
TrieTree.prototype = Object.freeze({
/*
function fetchingXHR() {
var xhr = new XMLHttpRequest();
var rejection = null;
var fetching = new Promise((resolve, reject) => {
rejection = reject;
xhr.open("GET", "http://example.com", true);
xhr.onload = function () {
resolve(xhr.responseText);

I’ll add the bellow section to https://github.com/mozilla/servo/wiki/JS-smart-pointers.

——————————————————————————————

How do we provide object graph to SpiderMonkey’s Gaberge Collection?

create

When Servo creates a Rusty DOM object, the binding code creates a wrapper JSObject which is created by SpiderMonkey, is correspond to each Rusty DOM Object. It’s produced and set to the Rusty object in FooBinding::Wrap.

In FooBinding::Wrap, the warpper JSObject gets the pointer for Rusty Object to itself. And the same time, the wrapper JSObject are set to the Rusty Object’s Reflector field (All Rusty DOM objects have dom::bindings::utils::Reflector in their most basis field). These step are the “binding” work to create the relationship of both objects.

@tetsuharuohzeki
tetsuharuohzeki / observer.js
Last active August 29, 2015 13:56
Performance benchmark for observer-js: https://github.com/saneyuki/observer-js/pull/32
/* vim: set filetype=javascript shiftwidth=4 tabstop=4 expandtab: */
/*
* @repository https://github.com/saneyuki/observer-js
* @version 0.4
* @license MIT License
*/
/*
* Copyright (c) 2014 Tetsuharu OHZEKI <saneyuki.snyk@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy