ScriptState::contextIsEmpty shouldn't return true for a context whose global object is detached

I cannot reproduce bug 385366 but my best guess is that V8AbstractEventListener::handleEvent calls context->Global() after the global object is detached from the context (because of the frame navigation).

Currently ScriptState is used in the following programming pattern:

class DOMObject {
  DOMObject(ScriptState* scriptState) : m_scriptState(scriptState) { }  // Record the script state when the DOMObject is created.

  void methodTriggeredAsynchrnously() {  // Blink calls this sometime later.
    if (m_scriptState->contextIsEmpty())  // If the context is already gone, we do nothing.
      return;
    ScriptState::Scope scope(m_scriptState.get());  // Otherwise, enter the context and do the actual work.
    ...; // Do the actual work.
  }

  RefPtr<ScriptState> m_scriptState;
};

The problem is that m_scriptState->contextIsEmpty() returns true even if the global object is detached from the context. We should return false in that case.

This CL also renames contextIsEmpty to contextIsValid for clarity.

BUG=385366

Review URL: https://codereview.chromium.org/538933002

git-svn-id: svn://svn.chromium.org/blink/trunk@181392 bbb929c8-8fbe-4397-9dbb-9b2b20218538