package com.google.gwt.modernizr.client.utils;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;

public class CanvasElement extends Element{

  static final String TAG = "canvas";

  /**
   * Assert that the given {@link Element} is compatible with this class and
   * automatically typecast it.
   */
  public static CanvasElement as(Element elem) {
    assert elem.getTagName().equalsIgnoreCase(TAG);
    return (CanvasElement) elem;
  }
  
  public static CanvasElement create(){
    return DOM.createElement(TAG).cast();
  }

  
  protected CanvasElement() {
  }

  public final native Object getContext(String ctxType) /*-{
    return this.getContext(ctxType);
  }-*/;

  public final native boolean isTextSupported()/*-{
    return !!(typeof this.getContext('2d').fillText == 'function');
  }-*/;

}

@@ -651,24 +651,54 @@
 xType) /*-%7B%0A
+    if (!!this.getContext)%7B%0A  
     return t
@@ -722,16 +722,39 @@
 xType);%0A
+    %7D%0A    return null;%0A
   %7D-*/;%0A

check if getContext method exist before calling it