Chromium Code Reviews| Index: lib/runtime/dart_runtime.js |
| diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js |
| index 468ac5dd7aabdfe7c4bef2a83ea2643f3b83f548..fd6a84d313f5faa955d81d8678cdb458e2076931 100644 |
| --- a/lib/runtime/dart_runtime.js |
| +++ b/lib/runtime/dart_runtime.js |
| @@ -18,6 +18,10 @@ var dart, _js_helper, _js_primitives, dartx; |
| const hasOwnProperty = Object.prototype.hasOwnProperty; |
| const slice = [].slice; |
| + let _constructorSig = Symbol('sigCtor'); |
| + let _methodSig = Symbol("sig"); |
| + let _staticSig = Symbol("sigStatic"); |
| + |
| function getOwnNamesAndSymbols(obj) { |
| return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); |
| } |
| @@ -754,7 +758,7 @@ var dart, _js_helper, _js_primitives, dartx; |
| get = null; |
| return cache; |
| } |
| - defineProperty(obj, name, {get : getter}); |
| + defineProperty(obj, name, {get: getter, configurable: true}); |
| } |
| function copyPropertiesHelper(to, from, names) { |
| @@ -773,11 +777,12 @@ var dart, _js_helper, _js_primitives, dartx; |
| } |
| dart.copyProperties = copyProperties; |
| - function getExtensionSymbol(name) { |
| + function extensionMember(name) { |
| let sym = dartx[name]; |
| if (!sym) dartx[name] = sym = Symbol('dartx.' + name); |
| return sym; |
| } |
| + dart.extensionMember = extensionMember; |
| /** |
| * Copy symbols from the prototype of the source to destination. |
| @@ -791,10 +796,7 @@ var dart, _js_helper, _js_primitives, dartx; |
| // Mark the JS type's instances so we can easily check for extensions. |
| assert(jsProto[_extensionType] === void 0); |
| jsProto[_extensionType] = extProto; |
| - for (let name of getOwnPropertyNames(extProto)) { |
| - let symbol = getExtensionSymbol(name); |
| - defineProperty(jsProto, symbol, getOwnPropertyDescriptor(extProto, name)); |
| - } |
| + copyPropertiesHelper(jsProto, extProto, getOwnPropertySymbols(extProto)); |
| } |
| dart.registerExtension = registerExtension; |
| @@ -815,14 +817,26 @@ var dart, _js_helper, _js_primitives, dartx; |
| */ |
| // TODO(jmesserly): essentially this gives two names to the same method. |
| // This benefit is roughly equivalent call performance either way, but the |
| - // cost is we need to call implementExtension any time a subclass overrides |
| + // cost is we need to call defineExtensionMEmbers any time a subclass overrides |
| // one of these methods. |
| function defineExtensionMembers(type, methodNames) { |
| let proto = type.prototype; |
| for (let name of methodNames) { |
| let method = getOwnPropertyDescriptor(proto, name); |
| - defineProperty(proto, getExtensionSymbol(name), method); |
| - } |
| + defineProperty(proto, extensionMember(name), method); |
| + } |
| + // Ensure the signature is available too. |
|
Leaf
2015/06/05 20:42:23
We could attach something to each method, but it s
Jennifer Messerly
2015/06/05 21:08:57
yeah, not sure in what sense it's wasteful, though
Jennifer Messerly
2015/06/05 21:10:34
also, wouldn't hypothetical Typed-ES likely work t
Leaf
2015/06/05 21:34:44
It's no big deal really. As it stands, we have a
|
| + // TODO(jmesserly): can we make this cleaner? Ideally signatures would be |
| + // associated with the methods, so copying the methods above would |
| + // automatically copy the type signature too. |
| + var originalSigFn = getOwnPropertyDescriptor(type, _methodSig).get; |
| + defineMemoizedGetter(type, _methodSig, function() { |
| + var sig = originalSigFn(); |
| + for (let name of methodNames) { |
| + sig[extensionMember(name)] = sig[name]; |
| + } |
| + return sig; |
| + }); |
| } |
| dart.defineExtensionMembers = defineExtensionMembers; |
| @@ -896,7 +910,7 @@ var dart, _js_helper, _js_primitives, dartx; |
| // Set the signature of the Mixin class to be the composition |
| // of the signatures of the mixins. |
| dart.setSignature(Mixin, { |
| - methods : () => { |
| + methods: () => { |
| let s = {}; |
| for (let m of mixins) { |
| copyProperties(s, m[_methodSig]); |
| @@ -1020,10 +1034,6 @@ var dart, _js_helper, _js_primitives, dartx; |
| } |
| dart.generic = generic; |
| - let _constructorSig = Symbol('sigCtor'); |
| - let _methodSig = Symbol("sig"); |
| - let _staticSig = Symbol("sigStatic"); |
| - |
| /// Get the type of a function using the store runtime type |
| function _getFunctionType(f) { |
| return f[_runtimeType]; |