JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
{
    HTMLCanvasElement& canvas = impl();
    const String& contextId = exec->argument(0).toString(exec)->value(exec);
    
    RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(WEBGL)
    if (HTMLCanvasElement::is3dType(contextId)) {
        get3DContextAttributes(exec, attrs);
        if (exec->hadException())
            return jsUndefined();
    }
#endif
    
    CanvasRenderingContext* context = canvas.getContext(contextId, attrs.get());
    if (!context)
        return jsNull();
    JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
    if (InspectorInstrumentation::canvasAgentEnabled(&canvas.document())) {
        Deprecated::ScriptObject contextObject(exec, jsValue.getObject());
        Deprecated::ScriptObject wrapped;
        if (context->is2d())
            wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(&canvas.document(), contextObject);
#if ENABLE(WEBGL)
        else if (context->is3d())
            wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(&canvas.document(), contextObject);
#endif
        if (!wrapped.hasNoValue())
            return wrapped.jsValue();
    }
    return jsValue;
}
void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<Inspector::TypeBuilder::Runtime::RemoteObject>& result)
{
    bool ok;
    unsigned id = heapSnapshotObjectId.toUInt(&ok);
    if (!ok) {
        *error = "Invalid heap snapshot object id";
        return;
    }
    Deprecated::ScriptObject heapObject = ScriptProfiler::objectByHeapObjectId(id);
    if (heapObject.hasNoValue()) {
        *error = "Object is not available";
        return;
    }
    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(heapObject.scriptState());
    if (injectedScript.hasNoValue()) {
        *error = "Object is not available. Inspected context is gone";
        return;
    }
    result = injectedScript.wrapObject(heapObject, objectGroup ? *objectGroup : "");
    if (!result)
        *error = "Failed to wrap object";
}