extern definition for measureText should return non-null
See original GitHub issueIn the extern html5.js the return type should be non-null. Add an exclamation point like this:
/**
* @param {string} text
* @return {!TextMetrics}
* @nosideeffects
*/
CanvasRenderingContext2D.prototype.measureText = function(text) {};
The spec for measureText makes no mention of possibly returning null.
This change helps avoid needing code like this:
var textMetrics = context.measureText(s);
if (!textMetrics) {
throw new Error();
}
var textWidth = textMetrics.width;
instead you can write
var textWidth = context.measureText(s).width;
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
CanvasRenderingContext2D.measureText() - Web APIs | MDN
measureText () method returns a TextMetrics object that contains information about the measured text (such as its width, for example).
Read more >core/java/android/text/TextUtils.java - platform/frameworks/base
public static String getEllipsisString(@NonNull TextUtils.TruncateAt method) {. return ... tokens is an empty array, an empty string will be returned.
Read more >TextUtils.java - Android Code Search
// Returns true if the character's presence could affect RTL layout. //. // In order to be fast, the code is intentionally rough...
Read more >Canvas Element - HTML Standard - WhatWG
Authors should not use the canvas element in a document when a more ... Returns an object that exposes an API for drawing...
Read more >go.d.ts - UNPKG
These collection classes were defined in GoJS before the ES6 collection classes were ... When this property is non-null, the #diagram property will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After thinking it over, I’ll modify the pull request to only change return values to be non-nullable, not parameter values. The question about non-nullable parameter values should be done on a separate issue and pull request.
Fixed by #2435