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

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

Issue 114363002: Structured cloning: improve DataCloneError reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased + reset V8TestInterfaceConstructor.cpp result Created 7 years 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex); 57 v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex);
58 if (cache->IsNull() || cache->IsUndefined()) { 58 if (cache->IsNull() || cache->IsUndefined()) {
59 cache = v8::Array::New(isolate); 59 cache = v8::Array::New(isolate);
60 object->SetInternalField(cacheIndex, cache); 60 object->SetInternalField(cacheIndex, cache);
61 } 61 }
62 62
63 v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache); 63 v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache);
64 cacheArray->Set(v8::Integer::New(cacheArray->Length(), isolate), value); 64 cacheArray->Set(v8::Integer::New(cacheArray->Length(), isolate), value);
65 } 65 }
66 66
67 bool extractTransferables(v8::Local<v8::Value> value, MessagePortArray& ports, A rrayBufferArray& arrayBuffers, bool& notASequence, v8::Isolate* isolate) 67 bool extractTransferables(v8::Local<v8::Value> value, int argumentIndex, Message PortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState , v8::Isolate* isolate)
68 { 68 {
69 if (isUndefinedOrNull(value)) { 69 if (isUndefinedOrNull(value)) {
70 ports.resize(0); 70 ports.resize(0);
71 arrayBuffers.resize(0); 71 arrayBuffers.resize(0);
72 return true; 72 return true;
73 } 73 }
74 74
75 uint32_t length = 0; 75 uint32_t length = 0;
76 if (value->IsArray()) { 76 if (value->IsArray()) {
77 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); 77 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value);
78 length = array->Length(); 78 length = array->Length();
79 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 79 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
80 notASequence = true; 80 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO rValue(argumentIndex + 1));
81 return false; 81 return false;
82 } 82 }
83 83
84 v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value); 84 v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value);
85 85
86 // Validate the passed array of transferrables. 86 // Validate the passed array of transferrables.
87 for (unsigned int i = 0; i < length; ++i) { 87 for (unsigned int i = 0; i < length; ++i) {
88 v8::Local<v8::Value> transferrable = transferrables->Get(i); 88 v8::Local<v8::Value> transferrable = transferrables->Get(i);
89 // Validation of non-null objects, per HTML5 spec 10.3.3. 89 // Validation of non-null objects, per HTML5 spec 10.3.3.
90 if (isUndefinedOrNull(transferrable)) { 90 if (isUndefinedOrNull(transferrable)) {
91 setDOMException(DataCloneError, isolate); 91 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ? "'undefined'" : "'null'") + " value.");
92 return false; 92 return false;
93 } 93 }
94 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15. 94 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15.
95 if (V8MessagePort::hasInstance(transferrable, isolate, worldType(isolate ))) { 95 if (V8MessagePort::hasInstance(transferrable, isolate, worldType(isolate ))) {
96 RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Ob ject>::Cast(transferrable)); 96 RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Ob ject>::Cast(transferrable));
97 // Check for duplicate MessagePorts. 97 // Check for duplicate MessagePorts.
98 if (ports.contains(port)) { 98 if (ports.contains(port)) {
99 setDOMException(DataCloneError, isolate); 99 exceptionState.throwDOMException(DataCloneError, "Message port a t index " + String::number(i) + " is a duplicate of an earlier port.");
100 return false; 100 return false;
101 } 101 }
102 ports.append(port.release()); 102 ports.append(port.release());
103 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate, worldType( isolate))) 103 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate, worldType( isolate)))
104 arrayBuffers.append(V8ArrayBuffer::toNative(v8::Handle<v8::Object>:: Cast(transferrable))); 104 arrayBuffers.append(V8ArrayBuffer::toNative(v8::Handle<v8::Object>:: Cast(transferrable)));
105 else { 105 else {
106 setDOMException(DataCloneError, isolate); 106 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type.");
107 return false; 107 return false;
108 } 108 }
109 } 109 }
110 return true; 110 return true;
111 } 111 }
112 112
113 bool getMessagePortArray(v8::Local<v8::Value> value, const String& propertyName, MessagePortArray& ports, v8::Isolate* isolate) 113 bool getMessagePortArray(v8::Local<v8::Value> value, const String& propertyName, MessagePortArray& ports, v8::Isolate* isolate)
114 { 114 {
115 if (isUndefinedOrNull(value)) { 115 if (isUndefinedOrNull(value)) {
116 ports.resize(0); 116 ports.resize(0);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 ExecutionContext* getExecutionContext() 173 ExecutionContext* getExecutionContext()
174 { 174 {
175 if (WorkerScriptController* controller = WorkerScriptController::controllerF orContext()) 175 if (WorkerScriptController* controller = WorkerScriptController::controllerF orContext())
176 return &controller->workerGlobalScope(); 176 return &controller->workerGlobalScope();
177 177
178 return currentDocument(); 178 return currentDocument();
179 } 179 }
180 180
181 } // namespace WebCore 181 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8Utilities.h ('k') | Source/bindings/v8/custom/V8DedicatedWorkerGlobalScopeCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698