question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extern definition for measureText should return non-null

See original GitHub issue

In 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:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
myphysicslabcommented, Apr 13, 2017

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.

0reactions
myphysicslabcommented, Apr 21, 2017

Fixed by #2435

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found