Re: spec verbosity and algorithms

On Fri, Jan 22, 2010 at 10:28 PM, Karl Dubost <karl@la-grange.net> wrote:
> [23:24]  <TabAtkins> karlcow: Yeah, it's wrong.  The opaque-identifier portion should completely separate from the same-components section.  If they're opaque, they don't *have* components.
> [23:25]  <karlcow> TabAtkins: ah. I'll modify. It is not clear in the prose of the spec I have the feeling.
> [23:25]  * karlcow likes to visualize to understand
> [23:26]  <TabAtkins> If you translate it from prose directly to if/then code in your favorite programming language, it becomes very clear.  ^_^

function sameOriginP(A,B) {
  if(opaque(A) && opaque(B) && A.value == B.value) {
    return true;}
  if(opaque(A) || opaque(B)) {
    return false;}
  if(A.scheme != B.scheme || A.host != B.host || A.port != B.port) {
    return false;}
  for(key in A.extraData) {
    if(A.extraData[key] != B.extraData[key]) {
      return false;}}
  for(key in B.extraData) {
    //have to do it both ways with this method, in case B has some
extra data that A doesn't.
    //there are probably better ways to handle this
    if(A.extraData[key] != B.extraData[key]) {
      return false;}}
  return true;
}

~TJ

Received on Saturday, 23 January 2010 04:38:28 UTC