Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tool/input_sdk/private/ddc_runtime/classes.dart

Issue 2061373003: implement user-defined nSM, Object members on functions (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// This library defines the operations that define and manipulate Dart 5 /// This library defines the operations that define and manipulate Dart
6 /// classes. Included in this are: 6 /// classes. Included in this are:
7 /// - Generics 7 /// - Generics
8 /// - Class metadata 8 /// - Class metadata
9 /// - Extension methods 9 /// - Extension methods
10 /// 10 ///
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // symbol name. 330 // symbol name.
331 var names = getOwnPropertyNames(coreObjProto); 331 var names = getOwnPropertyNames(coreObjProto);
332 for (int i = 0; i < JS('int', '#.length', names); ++i) { 332 for (int i = 0; i < JS('int', '#.length', names); ++i) {
333 var name = JS('', '#[#]', names, i); 333 var name = JS('', '#[#]', names, i);
334 var desc = getOwnPropertyDescriptor(coreObjProto, name); 334 var desc = getOwnPropertyDescriptor(coreObjProto, name);
335 defineProperty(jsProto, getExtensionSymbol(name), desc); 335 defineProperty(jsProto, getExtensionSymbol(name), desc);
336 } 336 }
337 return; 337 return;
338 } 338 }
339 339
340
341 ///
342 /// Copy symbols from the prototype of the source to destination. 340 /// Copy symbols from the prototype of the source to destination.
343 /// These are the only properties safe to copy onto an existing public 341 /// These are the only properties safe to copy onto an existing public
344 /// JavaScript class. 342 /// JavaScript class.
345 ///
346 registerExtension(jsType, dartExtType) => JS('', '''(() => { 343 registerExtension(jsType, dartExtType) => JS('', '''(() => {
347 // TODO(vsm): Not all registered js types are real. 344 // TODO(vsm): Not all registered js types are real.
348 if (!jsType) return; 345 if (!jsType) return;
349 346
350 let extProto = $dartExtType.prototype; 347 let extProto = $dartExtType.prototype;
351 let jsProto = $jsType.prototype; 348 let jsProto = $jsType.prototype;
352 349
353 // Mark the JS type's instances so we can easily check for extensions. 350 // Mark the JS type's instances so we can easily check for extensions.
354 jsProto[$_extensionType] = $dartExtType; 351 jsProto[$_extensionType] = $dartExtType;
355 $_installProperties(jsProto, extProto); 352 $_installProperties(jsProto, extProto);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 let originalSigFn = $getOwnPropertyDescriptor($type, $_methodSig).get; 394 let originalSigFn = $getOwnPropertyDescriptor($type, $_methodSig).get;
398 $defineMemoizedGetter(type, $_methodSig, function() { 395 $defineMemoizedGetter(type, $_methodSig, function() {
399 let sig = originalSigFn(); 396 let sig = originalSigFn();
400 for (let name of $methodNames) { 397 for (let name of $methodNames) {
401 sig[$getExtensionSymbol(name)] = sig[name]; 398 sig[$getExtensionSymbol(name)] = sig[name];
402 } 399 }
403 return sig; 400 return sig;
404 }); 401 });
405 })()'''); 402 })()''');
406 403
407 canonicalMember(obj, name) => JS('', '''(() => {
408 // Private names are symbols and are already canonical.
409 if (typeof name === 'symbol') return name;
410
411 if ($obj != null && $obj[$_extensionType]) return $dartx[$name];
412 // Check for certain names that we can't use in JS
413 if ($name == 'constructor' || $name == 'prototype') {
414 $name = '+' + $name;
415 }
416 return $name;
417 })()''');
418
419 /// Sets the type of `obj` to be `type` 404 /// Sets the type of `obj` to be `type`
420 setType(obj, type) { 405 setType(obj, type) {
421 JS('', '#.__proto__ = #.prototype', obj, type); 406 JS('', '#.__proto__ = #.prototype', obj, type);
422 return obj; 407 return obj;
423 } 408 }
424 409
425 /// Sets the element type of a list literal. 410 /// Sets the element type of a list literal.
426 list(obj, elementType) => 411 list(obj, elementType) =>
427 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); 412 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))');
428 413
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 /// 452 ///
468 /// For example it can be called with `new SomeClass.name(args)`. 453 /// For example it can be called with `new SomeClass.name(args)`.
469 /// 454 ///
470 /// The constructor 455 /// The constructor
471 defineNamedConstructorCallable(clazz, name, ctor) => JS('', '''(() => { 456 defineNamedConstructorCallable(clazz, name, ctor) => JS('', '''(() => {
472 ctor.prototype = $clazz.prototype; 457 ctor.prototype = $clazz.prototype;
473 // Use defineProperty so we don't hit a property defined on Function, 458 // Use defineProperty so we don't hit a property defined on Function,
474 // like `caller` and `arguments`. 459 // like `caller` and `arguments`.
475 $defineProperty($clazz, $name, { value: ctor, configurable: true }); 460 $defineProperty($clazz, $name, { value: ctor, configurable: true });
476 })()'''); 461 })()''');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698