Replica of Google V8's Promise implementation converted to javascript