Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: Source/bindings/v8/V8Utilities.cpp

Issue 19765010: postMessage() should throw a DataCloneError on invalid transferables (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/core/dom/MessagePort.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return false; 80 return false;
81 } 81 }
82 82
83 v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value); 83 v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value);
84 84
85 // Validate the passed array of transferrables. 85 // Validate the passed array of transferrables.
86 for (unsigned int i = 0; i < length; ++i) { 86 for (unsigned int i = 0; i < length; ++i) {
87 v8::Local<v8::Value> transferrable = transferrables->Get(i); 87 v8::Local<v8::Value> transferrable = transferrables->Get(i);
88 // Validation of non-null objects, per HTML5 spec 10.3.3. 88 // Validation of non-null objects, per HTML5 spec 10.3.3.
89 if (isUndefinedOrNull(transferrable)) { 89 if (isUndefinedOrNull(transferrable)) {
90 setDOMException(InvalidStateError, isolate); 90 setDOMException(DataCloneError, isolate);
91 return false; 91 return false;
92 } 92 }
93 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15. 93 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15.
94 if (V8MessagePort::HasInstance(transferrable, isolate, worldType(isolate ))) { 94 if (V8MessagePort::HasInstance(transferrable, isolate, worldType(isolate ))) {
95 RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Ob ject>::Cast(transferrable)); 95 RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Ob ject>::Cast(transferrable));
96 // Check for duplicate MessagePorts. 96 // Check for duplicate MessagePorts.
97 if (ports.contains(port)) { 97 if (ports.contains(port)) {
98 setDOMException(InvalidStateError, isolate); 98 setDOMException(DataCloneError, isolate);
99 return false; 99 return false;
100 } 100 }
101 ports.append(port.release()); 101 ports.append(port.release());
102 } else if (V8ArrayBuffer::HasInstance(transferrable, isolate, worldType( isolate))) 102 } else if (V8ArrayBuffer::HasInstance(transferrable, isolate, worldType( isolate)))
103 arrayBuffers.append(V8ArrayBuffer::toNative(v8::Handle<v8::Object>:: Cast(transferrable))); 103 arrayBuffers.append(V8ArrayBuffer::toNative(v8::Handle<v8::Object>:: Cast(transferrable)));
104 else { 104 else {
105 throwTypeError(isolate); 105 setDOMException(DataCloneError, isolate);
106 return false; 106 return false;
107 } 107 }
108 } 108 }
109 return true; 109 return true;
110 } 110 }
111 111
112 bool getMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& ports, v8 ::Isolate* isolate) 112 bool getMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& ports, v8 ::Isolate* isolate)
113 { 113 {
114 ArrayBufferArray arrayBuffers; 114 if (isUndefinedOrNull(value)) {
115 bool result = extractTransferables(value, ports, arrayBuffers, isolate); 115 ports.resize(0);
116 if (!result) 116 return true;
117 return false; 117 }
118 if (arrayBuffers.size() > 0) { 118 if (!value->IsArray()) {
119 throwTypeError("MessagePortArray argument must contain only MessagePorts ", isolate); 119 throwTypeError(isolate);
120 return false; 120 return false;
121 } 121 }
122 return true; 122 bool success = false;
123 ports = toRefPtrNativeArray<MessagePort, V8MessagePort>(value, isolate, &suc cess);
124 return success;
123 } 125 }
124 126
125 void removeHiddenDependency(v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex, v8::Isolate* isolate) 127 void removeHiddenDependency(v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex, v8::Isolate* isolate)
126 { 128 {
127 v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex); 129 v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex);
128 if (!cache->IsArray()) 130 if (!cache->IsArray())
129 return; 131 return;
130 v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache); 132 v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache);
131 for (int i = cacheArray->Length() - 1; i >= 0; --i) { 133 for (int i = cacheArray->Length() - 1; i >= 0; --i) {
132 v8::Local<v8::Value> cached = cacheArray->Get(v8::Integer::New(i, isolat e)); 134 v8::Local<v8::Value> cached = cacheArray->Get(v8::Integer::New(i, isolat e));
(...skipping 20 matching lines...) Expand all
153 155
154 ScriptExecutionContext* getScriptExecutionContext() 156 ScriptExecutionContext* getScriptExecutionContext()
155 { 157 {
156 if (WorkerScriptController* controller = WorkerScriptController::controllerF orContext()) 158 if (WorkerScriptController* controller = WorkerScriptController::controllerF orContext())
157 return controller->workerGlobalScope(); 159 return controller->workerGlobalScope();
158 160
159 return currentDocument(); 161 return currentDocument();
160 } 162 }
161 163
162 } // namespace WebCore 164 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/core/dom/MessagePort.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698